Skip to content

fix(desktop): apply custom keybinding changes without an app restart - #4621

Merged
Jocs merged 2 commits into
developfrom
fix/keybinding-reload-3681
Jun 22, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/keybinding-reload-3681

Conversation

@Jocs

@Jocs Jocs commented Jun 21, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #3681 — changing a custom keybinding in Preferences did not take effect until the app was restarted.

Keybindings.setUserKeybindings (packages/desktop/src/main/keyboard/shortcutHandler.ts) only wrote the new bindings to disk. The active keys map and the electron-localshortcut accelerators registered on each open window were rebuilt only by the Keybindings constructor, so a change applied solely on the next launch.

Changes

  • setUserKeybindings(userKeybindings, windows = []) now, after persisting, calls a new _reloadKeybindings(windows) that:
    • resets this.keys to the platform defaults first, then re-runs _loadLocalKeybindings(). This reset is required because _loadLocalKeybindings merges user accelerators onto the current map rather than recomputing from scratch — without the reset, a removed/changed binding would leave the old accelerator behind.
    • re-registers shortcuts on each open editor window. @hfelix/electron-localshortcut exposes no unregisterAll, so the previously registered accelerators are unregistered individually before the new set is registered, and destroyed windows are skipped.
  • The IPC handler mt::keybinding-save-user-keybindings (app/index.ts) now passes the open editor windows (getWindowsByType(WindowType.EDITOR)) so the reload targets live editor windows only (not the settings window).

Test

packages/desktop/test/unit/specs/keybinding-reload.spec.ts instantiates the real Keybindings against a temp config dir + a fake window and verifies:

  • after setUserKeybindings, the active map reflects the new accelerator and it is registered live on the open window (with the previous accelerators torn down first);
  • destroyed windows are skipped.

Written test-first (red → green). pnpm run typecheck and ESLint are clean on the changed files.

🤖 Generated with Claude Code

Jocs and others added 2 commits June 21, 2026 13:58
`setUserKeybindings` only persisted the new bindings to disk; the active
key map and the shortcuts registered on open windows were rebuilt solely
by the `Keybindings` constructor, so custom keybindings took effect only
after restarting the app.

Rebuild the key map from the defaults plus the just-saved user file (the
map is reset to defaults first because `_loadLocalKeybindings` merges
onto the current map) and re-register shortcuts on the open editor
windows. `@hfelix/electron-localshortcut` has no `unregisterAll`, so the
previously registered accelerators are torn down individually before the
new set is registered.

Fixes #3681

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Instantiate the real `Keybindings` against a temp config dir and a fake
window, then assert that saving new user keybindings updates the active
key map and re-registers shortcuts on open windows (and skips destroyed
ones) — i.e. changes apply without a restart.

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

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4621:

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

Artifact Size Link
marktext-windows-arm64 275.8 MB Download
marktext-linux 627.4 MB Download
marktext-windows-x64 283.9 MB Download
marktext-macos-x64 293.0 MB Download
marktext-macos-arm64 282.7 MB Download

@Jocs
Jocs merged commit ac568f1 into develop Jun 22, 2026
10 checks passed
@Jocs
Jocs deleted the fix/keybinding-reload-3681 branch June 22, 2026 02:08
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.

Set key binding fails

1 participant