Repository navigation
fix: sync the inline format toolbar with custom keybindings - #4862
FurkaanBoraa wants to merge 3 commits into
Conversation
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.
…#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
…anguage detection Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016i2jUQCojwMDpv3WLKzzb5
…#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.
…anguage detection
|
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. |
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)inlineFormatShortcutsoption: per format type, a tooltiplabelplus an optionalkey/shiftKey/altKeymatcher 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-existingmuya.setOptions(...)mechanism. The toolbar resolves both the tooltip hint and the keydown matching through this map.format*beforeinputon 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.tsconverts themt::keybindings-responsemap (command id → Electron accelerator) into the muya option: labels via the sameacceleratorToTokensthe 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.mt::keybindings-responseon the renderer bus;editor.vuepushes 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
KeyboardEvent.keyarrives uppercase with Shift held, so the old lowercase-keyed map could never match them.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 claimedCtrl+`).Tests
src/ui/inlineFormatToolbar/__tests__/shortcutOverrides.spec.ts— tooltip fallback / override / empty-label / runtimesetOptions, plus the internal handler's default, rebound, matcher-less, Shift-uppercase and Alt-mismatch paths.src/editor/__tests__/nativeFormatSuppression.spec.ts—format*beforeinputs are cancelled; text insertion, composition and history inputTypes pass through.test/unit/specs/inline-format-shortcuts.spec.ts— accelerator → map conversion across platforms, modifiers, unbound and inexpressible combos.Verification
test(1415) /lint/lint:types/check-circular; desktoplint/typecheck/test:unit(721).isOsxfalse 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.