diff --git a/apps/desktop/src/renderer/features/editor/TiptapEditor.tsx b/apps/desktop/src/renderer/features/editor/TiptapEditor.tsx index 689cb78..4d4783c 100644 --- a/apps/desktop/src/renderer/features/editor/TiptapEditor.tsx +++ b/apps/desktop/src/renderer/features/editor/TiptapEditor.tsx @@ -69,6 +69,8 @@ export function TiptapEditor() { ], content: useStore.getState().body, editorProps: { + // 关闭 Chromium 内置拼写检查——contenteditable 默认开启,会对英文技术词画红色波浪线 + attributes: { spellcheck: 'false' }, // FR-E6:剪贴板粘贴图片 -> 入库 .attachments -> 插入相对路径 handlePaste: (_view, event) => { const ev = event as ClipboardEvent; diff --git a/apps/desktop/src/renderer/styles.css b/apps/desktop/src/renderer/styles.css index 4b822e6..893aed9 100644 --- a/apps/desktop/src/renderer/styles.css +++ b/apps/desktop/src/renderer/styles.css @@ -31,6 +31,13 @@ svg { display: block; } margin: 0 auto; caret-color: var(--accent); } +/* 兜底:去掉拼写/语法错误的红色波浪下划线(即使个别 contenteditable 仍开启 spellcheck) */ +.tiptap-wrap [contenteditable="true"] :spelling-error, +.tiptap-wrap [contenteditable="true"] :grammar-error, +.tiptap-wrap .ProseMirror :spelling-error, +.tiptap-wrap .ProseMirror :grammar-error { + text-decoration: none; +} .tiptap-wrap .ProseMirror p { margin: 0.6em 0; } .tiptap-wrap .ProseMirror h1 { font-size: 1.8em; margin: 1em 0 0.5em; font-weight: 700; color: var(--text-primary); padding-bottom: 0.25em; border-bottom: 1px solid var(--control-border); } .tiptap-wrap .ProseMirror h2 { font-size: 1.5em; margin: 0.9em 0 0.45em; font-weight: 600; color: var(--text-primary); } diff --git a/apps/desktop/tests/e2e/spellcheck-check.spec.ts b/apps/desktop/tests/e2e/spellcheck-check.spec.ts new file mode 100644 index 0000000..770cf0d --- /dev/null +++ b/apps/desktop/tests/e2e/spellcheck-check.spec.ts @@ -0,0 +1,52 @@ +import { test, expect } from '@playwright/test'; +import { _electron as electron } from 'playwright'; +import { promises as fs } from 'node:fs'; +import nodePath from 'node:path'; +import os from 'node:os'; + +const MAIN_JS = nodePath.join(process.cwd(), 'dist-electron/main/index.js'); + +async function launch(userData: string) { + const app = await electron.launch({ args: ['--user-data-dir=' + userData, MAIN_JS] }); + const page = await app.firstWindow(); + await page.waitForLoadState('domcontentloaded'); + const invoke = (ch: string, args: any) => page.evaluate(({ ch, args }) => (globalThis as any).dsh.invoke(ch, args), { ch, args }); + return { app, page, invoke }; +} + +// 红色波浪线修复:编辑器 contenteditable 必须关闭 Chromium 拼写检查(spellcheck=false) +test('编辑器关闭拼写检查(去除红色波浪线)', async () => { + const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-sp-')); + const ud = nodePath.join(tmp, 'ud'); const v = nodePath.join(tmp, 'v'); + await fs.mkdir(ud, { recursive: true }); await fs.mkdir(v, { recursive: true }); + const a = await launch(ud); + await a.invoke('vault:switch', { root: v }); + await a.page.getByRole('button', { name: /新建文档/ }).click(); + await a.page.getByPlaceholder(/输入文档标题/).fill('SpellTest'); + await a.page.getByPlaceholder(/输入文档标题/).press('Enter'); + await expect(a.page.getByTestId('tabbar').getByText('SpellTest', { exact: true })).toBeVisible({ timeout: 10000 }); + const ed = a.page.locator('.ProseMirror'); + await ed.click(); + await a.page.keyboard.type('WordPress caddy gitea Lsky'); + await a.page.waitForTimeout(300); + // 主编辑器 spellcheck 属性必须为 false(Chromium 据此关闭红色波浪线) + const sc = await a.page.locator('.ProseMirror').getAttribute('spellcheck'); + console.log('SPELLCHECK', sc); + expect(sc).toBe('false'); + // CSS 兜底样式存在:spelling-error / grammar-error 无红色波浪下划线 + const cssOk = await a.page.evaluate(() => { + const sheets = Array.from(document.styleSheets); + for (const s of sheets) { + try { + const rules = Array.from((s as CSSStyleSheet).cssRules); + for (const r of rules) { + const css = (r as CSSStyleRule).cssText || ''; + if (css.includes('spelling-error') && css.includes('text-decoration')) return true; + } + } catch { /* cross-origin */ } + } + return false; + }); + console.log('CSS_FALLBACK', cssOk); + await a.app.close(); +}); \ No newline at end of file