Repository navigation
fix(desktop): apply custom keybinding changes without an app restart - #4621
Merged
Merged
Conversation
`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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 activekeysmap and theelectron-localshortcutaccelerators registered on each open window were rebuilt only by theKeybindingsconstructor, so a change applied solely on the next launch.Changes
setUserKeybindings(userKeybindings, windows = [])now, after persisting, calls a new_reloadKeybindings(windows)that:this.keysto the platform defaults first, then re-runs_loadLocalKeybindings(). This reset is required because_loadLocalKeybindingsmerges user accelerators onto the current map rather than recomputing from scratch — without the reset, a removed/changed binding would leave the old accelerator behind.@hfelix/electron-localshortcutexposes nounregisterAll, so the previously registered accelerators are unregistered individually before the new set is registered, and destroyed windows are skipped.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.tsinstantiates the realKeybindingsagainst a temp config dir + a fake window and verifies:setUserKeybindings, the active map reflects the new accelerator and it is registered live on the open window (with the previous accelerators torn down first);Written test-first (red → green).
pnpm run typecheckand ESLint are clean on the changed files.🤖 Generated with Claude Code