Skip to content

fix: sync the inline format toolbar with custom keybindings - #4862

Closed
FurkaanBoraa wants to merge 3 commits into
marktext:developfrom
FurkaanBoraa:fix/inline-format-toolbar-keybindings
Closed

FurkaanBoraa wants to merge 3 commits into
marktext:developfrom
FurkaanBoraa:fix/inline-format-toolbar-keybindings

Conversation

@FurkaanBoraa

Copy link
Copy Markdown
Contributor

Problem

Fixes #4687.

The inline format toolbar hardcodes its shortcut hints (inlineFormatToolbar/config.ts) and applies format shortcuts through a hardcoded internal key map (FORMAT_SHORTCUTS / FORMAT_SHORTCUTS_SHIFT). After rebinding a format command in Preferences → Keybindings:

Hand-testing the fix surfaced a third leak behind the same combo: once the old accelerator no longer claims the key (and the toolbar handler correctly stops matching it), the keystroke reaches the contenteditable and Chromium's native rich-text editing bolds the DOM directly — visible styling that lives outside the document model and never reaches the serialized markdown.

Fix

Following the direction sketched in the issue, the engine stays unaware of the desktop key map:

muya (@muyajs/core)

  • New optional inlineFormatShortcuts option: per format type, a tooltip label plus an optional key/shiftKey/altKey matcher for the internal Cmd/Ctrl-gated handler. Missing types keep the bundled defaults, so standalone muya (examples, website) is unaffected; runtime changes go through the pre-existing muya.setOptions(...) mechanism. The toolbar resolves both the tooltip hint and the keydown matching through this map.
  • The editor now cancels every format* beforeinput on the contenteditable — the document model is the only writer of formatting, so the browser's native Cmd/Ctrl+B/I/U editing must never mutate the DOM behind it.

desktop

  • util/formatShortcuts.ts converts the mt::keybindings-response map (command id → Electron accelerator) into the muya option: labels via the same acceleratorToTokens the command palette uses; a key matcher only when the combo is expressible for the internal handler (Cmd/Ctrl + optional Shift/Alt + a single printable key) — anything else stays hint-only and owned by the application menu.
  • The editor store re-broadcasts mt::keybindings-response on the renderer bus; editor.vue pushes the rebuilt map into the engine at mount and on every keybindings save, so the toolbar follows live without a restart.

Deliberate engine-default changes

  • The internal handler's defaults now match the advertised defaults: inline code is Cmd/Ctrl+` and inline math Shift+Cmd/Ctrl+M (the handler still listened for the pre-选中文字时的弹出选项快捷键和快捷键设置中的不统一 #3630 Cmd/Ctrl+E variants).
  • Key matching is case-insensitive, so the Shift-modified defaults (highlight, inline math, image, clear) actually fire now — KeyboardEvent.key arrives uppercase with Shift held, so the old lowercase-keyed map could never match them.
  • The Alt state must match, so Ctrl+Alt combos (AltGr on Windows layouts) no longer trigger formats bound to Ctrl-only combos.

In the desktop app these combos are normally consumed by the application menu before reaching the DOM, so the default changes matter mainly for standalone muya embedders.

Platform note

The map is built from the live per-platform bindings, so Linux's inline-code tooltip now correctly shows Ctrl+Y (the hardcoded hint claimed Ctrl+` ).

Tests

  • muya src/ui/inlineFormatToolbar/__tests__/shortcutOverrides.spec.ts — tooltip fallback / override / empty-label / runtime setOptions, plus the internal handler's default, rebound, matcher-less, Shift-uppercase and Alt-mismatch paths.
  • muya src/editor/__tests__/nativeFormatSuppression.spec.ts — format* beforeinputs are cancelled; text insertion, composition and history inputTypes pass through.
  • desktop test/unit/specs/inline-format-shortcuts.spec.ts — accelerator → map conversion across platforms, modifiers, unbound and inexpressible combos.

Verification

  • Suites green: muya test (1415) / lint / lint:types / check-circular; desktop lint / typecheck / test:unit (721).
  • Manually verified on macOS (dev build): rebound Bold away from ⌘B → the toolbar tooltip follows the new binding live, the new combo applies bold, and the old ⌘B neither formats through muya nor through Chromium's native editing.
  • Windows/Linux behavior is code-confirmed and unit-tested (isOsx false paths); I don't have the hardware for a hands-on check.

While hand-testing we also found a separate, pre-existing recorder bug in the keybindings dialog (Shift is silently dropped when recording digit/punctuation combos, e.g. pressing ⌘⇧7 records ⌘+7); it is unrelated to this change and will be filed as its own issue.

The floating format toolbar advertised hardcoded shortcut hints and applied
a hardcoded internal key map, so rebinding a format command in
Preferences -> Keybindings left the tooltip showing the stale default and
kept the old combo applying the format (marktext#4687).

muya now accepts an optional inlineFormatShortcuts map (per format type:
tooltip label + internal-handler key matcher) falling back to the bundled
defaults; the desktop builds that map from the keybindings the main process
broadcasts and pushes updates through muya.setOptions.
Once a format combo is no longer claimed by an embedder accelerator or the
toolbar's internal handler (e.g. Cmd+B after rebinding Bold), the keystroke
reaches the contenteditable and Chromium's native rich-text editing styles
the DOM behind the model's back — visible bold that never reaches the
serialized markdown. Cancel every format* beforeinput; the document model
is the only writer of formatting.
…default

The engine's internal handler now follows the ADVERTISED binding
(Cmd/Ctrl+`), so the spec locking legacy Cmd/Ctrl+E fails by design.
Assert the new default, lock that Cmd/Ctrl+E no longer applies, and add
a Shift-combo case (possible since matching became case-insensitive).
Also gate the shared triple-click helper on a settled selection — the
keystroke racing the selection is the known flake in this suite.
niyo-oyin added a commit to niyo-oyin/marktext-ja that referenced this pull request Jul 30, 2026
…#4862)

Apply upstream PR marktext#4862 (clean apply except an import-order conflict in
editor.vue). The toolbar hardcoded its tooltip hints and its internal
Cmd/Ctrl key map, so rebinding a format command left the old combo both
advertised and functional, and once the old accelerator stopped claiming
the key, Chromium's native rich-text editing bolded the DOM behind the
document model. The engine now takes an inlineFormatShortcuts option
(tooltip label + optional key matcher, live-updatable via setOptions),
the desktop feeds it from the mt::keybindings-response map at mount and
on every keybindings save, and the editor cancels every format*
beforeinput on the contenteditable.

Verified live on this Linux build: the inline-code tooltip shows the
actual Ctrl+Y binding (the hardcoded hint claimed Ctrl+`), localized
through muya's i18n. Suites: muya 1586, desktop 806, muya e2e shortcuts
6/6.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016i2jUQCojwMDpv3WLKzzb5
niyo-oyin added a commit to niyo-oyin/marktext-ja that referenced this pull request Jul 30, 2026
…#4862)

Apply upstream PR marktext#4862 (clean apply except an import-order conflict in
editor.vue). The toolbar hardcoded its tooltip hints and its internal
Cmd/Ctrl key map, so rebinding a format command left the old combo both
advertised and functional, and once the old accelerator stopped claiming
the key, Chromium's native rich-text editing bolded the DOM behind the
document model. The engine now takes an inlineFormatShortcuts option
(tooltip label + optional key matcher, live-updatable via setOptions),
the desktop feeds it from the mt::keybindings-response map at mount and
on every keybindings save, and the editor cancels every format*
beforeinput on the contenteditable.

Verified live on this Linux build: the inline-code tooltip shows the
actual Ctrl+Y binding (the hardcoded hint claimed Ctrl+`), localized
through muya's i18n. Suites: muya 1586, desktop 806, muya e2e shortcuts
6/6.
niyo-oyin added a commit to niyo-oyin/marktext-ja that referenced this pull request Jul 30, 2026
@Jocs

Jocs commented Oct 26, 2026

Copy link
Copy Markdown
Member

Thank you, @FurkaanBoraa, for the implementation and the detailed investigation, especially identifying Chromium's native-formatting fallback and adding regression coverage for it.

We are consolidating this work into a broader shortcut consistency change tracked in #2999 and #5887. The design covers the inline format toolbar, paragraph front menu, and quick insert menu together: MarkText will own keyboard command handling, while all three Muya surfaces will display the active desktop bindings, including changes and unbound commands.

We will use your findings and relevant tests when integrating the native-formatting protection. The broader design is still under review and has not landed yet.

Closing this PR so the unified implementation can proceed in one place. Thanks again for the contribution and for uncovering the additional behavior issue.

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.

[Bug] muya inline format toolbar shortcut hints don't follow custom keybindings

2 participants