Skip to content

fix(editor): reflect selection formatting in the toolbar - #34940

Closed
OrcaWin wants to merge 3 commits into
mainfrom
OrcaWin/editor-toolbar-formatting-state
Closed

OrcaWin wants to merge 3 commits into
mainfrom
OrcaWin/editor-toolbar-formatting-state

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​175 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​163
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​48 $\color{#cf222e}{\Huge{\mathbf{−}}}$​34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14

The rich Markdown toolbar currently renders every formatting button as inactive. Moving the caret into a heading, bold text or a list gives no formatting feedback, and assistive technologies cannot tell which toggle is pressed.

Subscribe within the toolbar to the existing editor-state selector and render the current block/mark/list flags through the existing active style and aria-pressed. Link and image remain ordinary action buttons. The selector compares formatting values so ordinary text changes do not rerender the toolbar or require transaction renders of the parent editor.

Evidence

The same hidden Electron editor, document and caret position before and after:

Before (caret in the heading, Heading 1 unmarked):

Before formatting feedback

After (Heading 1 visibly active):

After formatting feedback

The DOM reports the identical HTML and text selection (anchor:1, head:1); the baseline has no pressed state and the changed heading button reports aria-pressed=true.

Validation

Four real-editor tests fail on the baseline and pass with this change. Coverage includes caret transitions across headings and marks, toolbar Bold command, exact content, undo/redo, stored marks, list changes and nested quote/list state. A React Profiler verifies zero toolbar commits across four ordinary inserts plus unrelated transaction metadata, and one commit for a changed formatting flag. This measures React commits, not total editor CPU or native assistive-technology behavior.

ORCA_BACKGROUND_LAUNCH=1 pnpm test src/renderer/src/components/editor/RichMarkdownToolbar.test.tsx --maxWorkers=1

Rendered proof was captured through Playwright CDP in the verified worktree app with ORCA_BACKGROUND_LAUNCH=1, without native-window activation. Uses existing toolbar styles and the application tooltip provider. No host, protocol or workspace-kind changes; desktop platforms share the component. Mobile has its own formatting controls. The combined local checkout passed all 21 required checks with ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --maxWorkers=2 (73489de71f06). This includes formatting, lint, affected tests, typechecking and repository ratchets. Individual draft CI skips broad workflows; the result above is local combined validation. This PR remains draft for review.

Integration coverage

The full-editor focus-leave fixture now supplies the app-root TooltipProvider, matching the documented mounting contract after removing the nested per-button providers. The repository launcher passes all seven toolbar/focus-leave tests independently on the pinned base; the combined seven-suite batch passes 60 tests.

@OrcaWin

OrcaWin commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

Closing after adversarial review (primary reviewer + independent verifier), judged against origin/main and the optimization criteria in discussion #27143.

This is not a bug fix. It reintroduces the active-state toolbar UX that maintainers removed on purpose in #833/#834, and it adds crash risk by removing nested TooltipProviders for a component rendered from multiple roots. Close.

@OrcaWin OrcaWin closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant