From 938ceae84223a0a7be77720359f2dabdacf97bb8 Mon Sep 17 00:00:00 2001 From: boojack Date: Mon, 16 Nov 2026 09:01:17 +0800 Subject: [PATCH] fix(editor): remove mode indicator and source background --- web/src/components/MemoEditor/README.md | 5 ++- .../MemoEditor/edit/Toolbar/EditorToolbar.tsx | 6 --- .../MemoEditor/edit/Toolbar/InsertMenu.tsx | 4 +- web/src/lib/markdownStyles.ts | 2 +- web/tests/browser/editor-style.config.ts | 8 ++++ web/tests/browser/editor-style.html | 40 +++++++++++++++++++ web/tests/browser/editor-style.spec.ts | 28 +++++++++++++ web/tests/memo-editor-source-mode.test.tsx | 6 +-- 8 files changed, 85 insertions(+), 14 deletions(-) create mode 100644 web/tests/browser/editor-style.config.ts create mode 100644 web/tests/browser/editor-style.html create mode 100644 web/tests/browser/editor-style.spec.ts diff --git a/web/src/components/MemoEditor/README.md b/web/src/components/MemoEditor/README.md index 3f435ff84..a34ba8b15 100644 --- a/web/src/components/MemoEditor/README.md +++ b/web/src/components/MemoEditor/README.md @@ -27,7 +27,7 @@ MemoEditor memo level: name | draft seed, mode, data, draft stor - **`view/`** is the read-only surface over `MemoMarkdown`: tags and mentions navigate, in-memo anchors scroll, a paragraph that is one bare link becomes a preview card through the editor's block view (`linkCards.ts`), the page's search matches are painted, and heading ids match the outline. Tag and mention clicks arrive through the editor's `onClick` callbacks. Read-only tags with a click handler are focusable buttons; Enter activates on press and Space on release through the same click callback. Editable tags remain text. Nothing in memos matches the editor's class names or mutates its DOM. Previews that have Markdown but no memo query (the link-memo search, the share image) use `MemoContentView` directly. - **`edit/`** is the editing surface: `EditSession` renders the chrome (timestamp, attachments, suggestions, toolbar, focus mode, audio recording) over the draft store `MemoEditor` provides, persists the draft while open, and saves through the memo mutations. `Editor.tsx` is the composer's editor: `MemoMarkdown` editable with the composer's own extensions (`#tag` and `:emoji` autocomplete, file paste and drop), behind the `EditorController` contract in `controller.ts`. -Memo content uses 16px text on 24px lines with 12px between blocks; the editor keeps list rows compact. Code blocks use the full `well` fill so they remain distinct from the surrounding surface in Dark. Task items use `control-edge` for their checkbox border and darken Dark's pale accent behind the editor's white checkmark. Callouts use the app's accent, success, warning and danger colors. Custom tag tints bound lightness and sRGB channels so black and white remain visible across themes without coloring the text. +Memo content uses 16px text on 24px lines with 12px between blocks; the editor keeps list rows compact. Rich-text code blocks use the full `well` fill so they remain distinct from the surrounding surface in Dark; Markdown source mode stays transparent. Task items use `control-edge` for their checkbox border and darken Dark's pale accent behind the editor's white checkmark. Callouts use the app's accent, success, warning and danger colors. Custom tag tints bound lightness and sRGB channels so black and white remain visible across themes without coloring the text. Code blocks use lazy-loaded `@pierre/highlights` tokens as editor decorations, without an HTML conversion. GitHub Light and GitHub Dark Dimmed colors follow the document's color scheme; ordinary text and structural punctuation keep the editor's text color. Unsupported languages, unavailable WebAssembly, or browsers without `light-dark()` colors leave the code as plain text. Highlighting never changes the saved Markdown. @@ -49,7 +49,7 @@ A reducer (`edit/state/reducer.ts`) drives an external store; consumers subscrib ### Formatting and source mode -Formatting is the editor's own: its toolbar appears over selected text, the slash menu and Markdown shortcuts change block types, and its keys cover the rest. The editor's `mode` option shows the whole memo as Markdown text, with its syntax highlighted, and edits it as text; `useSourceMode` (`@/hooks/useSourceMode`) keeps the choice in the account's `EDITOR` user setting (`source_mode`), so it follows the user to every device; a switch applies at once and reverts if saving fails, and Settings → Editor changes the same value. To people it is "Markdown mode", the + menu's item with the code glyph (Lucide `CodeXml`), checked while on; in code it keeps the editor's name, source mode. A small, noninteractive `Markdown` label sits beside the commit button while source mode is on, where it never covers the text. Switching changes no text and emits no change. In source mode the toolbar, slash menu, block handle and link card do not show; the `#tag` and `:emoji` popups open as in rich mode, the formatting keys edit the Markdown, and the checklist chip toggles the task marker on the caret's line through the same `toggleTaskList` command. The controller reads tags and checklists from the text parsed as a memo. The source text is in the body font (the editor's `sourceFont` token is left at its default) so a switch keeps the text's rhythm; nothing in memos targets the editor's source classes. +Formatting is the editor's own: its toolbar appears over selected text, the slash menu and Markdown shortcuts change block types, and its keys cover the rest. The editor's `mode` option shows the whole memo as Markdown text, with its syntax highlighted, and edits it as text; `useSourceMode` (`@/hooks/useSourceMode`) keeps the choice in the account's `EDITOR` user setting (`source_mode`), so it follows the user to every device; a switch applies at once and reverts if saving fails, and Settings → Editor changes the same value. To people it is "Markdown mode", the + menu's item with the code glyph (Lucide `CodeXml`), checked while on; in code it keeps the editor's name, source mode. Switching changes no text and emits no change. In source mode the toolbar, slash menu, block handle and link card do not show; the `#tag` and `:emoji` popups open as in rich mode, the formatting keys edit the Markdown, and the checklist chip toggles the task marker on the caret's line through the same `toggleTaskList` command. The controller reads tags and checklists from the text parsed as a memo. The source text is in the body font (the editor's `sourceFont` token is left at its default) so a switch keeps the text's rhythm; nothing in memos targets the editor's source classes. ### Saving @@ -124,6 +124,7 @@ MemoEditor/ ## Testing - `tests/memo-record.test.tsx`: reads by name, freshness, optimistic patches, the comment mutations. +- `tests/browser/editor-style.spec.ts`: source-mode transparency and rich-text code backgrounds in Light, Dark and Paper; run `pnpm exec playwright test --config tests/browser/editor-style.config.ts` from `web/`. - `tests/memo-editor-view.test.tsx`: view mode by name, task ticking through the mutation. - `tests/memo-content-view.test.tsx`, `tests/editor.test.tsx`: the surfaces over the binding. - `tests/use-memo-init.test.tsx`, `tests/draft-key.test.ts`, `tests/use-auto-save.test.tsx`: drafts and keys. diff --git a/web/src/components/MemoEditor/edit/Toolbar/EditorToolbar.tsx b/web/src/components/MemoEditor/edit/Toolbar/EditorToolbar.tsx index b445ec005..d4aed8faa 100644 --- a/web/src/components/MemoEditor/edit/Toolbar/EditorToolbar.tsx +++ b/web/src/components/MemoEditor/edit/Toolbar/EditorToolbar.tsx @@ -132,12 +132,6 @@ export const EditorToolbar: FC = ({
- {/* Markdown mode is said beside the commit button, where it never covers the text. */} - {sourceMode.isSourceMode && ( - - Markdown - - )} {onCancel && (