Skip to content

fix(keybinding): sync menu bar and command palette when keybindings change - #4681

Merged
Jocs merged 2 commits into
developfrom
fix/3998-keybinding-menu-sync
Jun 24, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/3998-keybinding-menu-sync

Conversation

@Jocs

@Jocs Jocs commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #3998 — after a user customizes a keyboard shortcut in Preferences, the change was persisted and re-registered, but the application menu bar (and the command palette) kept showing the old accelerator until the app was restarted.

Root cause: the application menu is built once at startup with accelerators baked in from keybindings.getAccelerator(id). The save handler (mt::keybinding-save-user-keybindings → Keybindings.setUserKeybindings) updated the in-memory key map and re-registered the local shortcuts, but never rebuilt the menu.

Changes

  • AppMenu.updateKeybindings() (new): rebuilds every window menu — editor menus on all platforms and the macOS settings-window menu — so accelerators are re-read from the live keybinding map, and re-applies the active window's menu. Editor menus preserve their runtime toggle state (source-code / typewriter / focus / sidebar / tab-bar).
  • Save handler: after setUserKeybindings, calls menu.updateKeybindings() and pushes the refreshed accelerator map to editor windows via mt::keybindings-response, so the command palette (which renders entry.shortcut) updates too.

Places that now update live (no restart)

  • Editor menu bar (Windows / Linux) and macOS application menu
  • macOS settings-window application menu
  • Command palette shortcut hints

Known limitation (not addressed here)

muya's inline format toolbar (the floating bold/italic/… bar) shows shortcut hints that are hardcoded in packages/muya/src/ui/inlineFormatToolbar/config.ts and decoupled from the desktop keybinding system (they're hand-aligned to the default bindings). Those hints do not follow user customizations. This spans the self-contained @muyajs/core engine (whose design keeps the engine unaware of the desktop key map) and is intentionally left out of this PR. There is also a latent behavior nuance there: muya's internal FORMAT_SHORTCUTS can still fire the old default format shortcut after a rebind. Tracked as a follow-up.

Testing

  • New unit test keybinding-menu-rebuild.spec.ts (TDD: red → green) covering editor + settings menu rebuild and re-application of the active menu.
  • Existing keybinding-reload.spec.ts and application-menu-state.spec.ts pass; typecheck and lint clean.
  • Manually verified in electron dev: changing a shortcut updates the menu bar and command palette without restart.

🤖 Generated with Claude Code

Jocs and others added 2 commits June 24, 2026 21:34
…nt bindings

Rebuild every window menu (editor + macOS settings) so accelerators are
re-read from the live keybinding map, re-applying the active window's menu.
Editor menus preserve their runtime toggle state. This is the capability the
keybinding-save flow needs to refresh the menu bar without a restart (#3998).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
After persisting user keybindings, rebuild the application menu via
AppMenu.updateKeybindings() and push the refreshed accelerator map to editor
windows so the command palette updates too. Previously the new bindings only
took effect after an app restart, so the menu bar and command palette kept
showing the old shortcuts (#3998).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4681:

Run: https://github.com/marktext/marktext/actions/runs/28102515435

Artifact Size Link
marktext-windows-arm64 275.6 MB Download
marktext-linux 627.2 MB Download
marktext-macos-x64 292.9 MB Download
marktext-windows-x64 283.8 MB Download
marktext-macos-arm64 282.6 MB Download

@Jocs
Jocs merged commit d313298 into develop Jun 24, 2026
10 checks passed
@Jocs
Jocs deleted the fix/3998-keybinding-menu-sync branch June 24, 2026 14:50
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