fix: capitalize accelerator modifiers to fix custom keybindings#4134
Open
Bowl42 wants to merge 2 commits into
Open
fix: capitalize accelerator modifiers to fix custom keybindings#4134Bowl42 wants to merge 2 commits into
Bowl42 wants to merge 2 commits into
Conversation
…text#4123) The keybinding UI captured keyboard shortcuts with lowercase modifier names (e.g. "ctrl+alt+1") via getAcceleratorFromKeyboardEvent(), but Electron requires properly capitalized modifiers (e.g. "Ctrl+Alt+1"). - Add capitalizeAccelerator() utility to normalize modifier casing - Apply capitalization in key-input-dialog before saving - Fix _isDefaultBinding to use case-insensitive comparison - Add comprehensive unit tests for capitalizeAccelerator Fixes marktext#4123 Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Apply capitalizeAccelerator when loading user keybindings from disk, healing legacy files that contain lowercase modifiers - Fix JSDoc: clarify that only modifiers are capitalized, not key names - Fix comment: map contains modifier names only - Add missing test cases: single modifier without key, Plus key, non-modifier special keys, idempotency Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes custom keybinding registration failures caused by lowercase modifier names (e.g. ctrl+alt+1) by normalizing accelerator modifier casing to Electron’s expected format and ensuring default-binding comparisons are case-insensitive.
Changes:
- Added
capitalizeAccelerator()utility insrc/common/keybinding/index.jsto normalize modifier casing. - Applied accelerator capitalization when capturing shortcuts in the preferences UI and when loading legacy
keybindings.jsonentries. - Updated default binding detection to use
isEqualAcceleratorand added unit tests for the new utility.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/unit/specs/capitalize-accelerator.spec.js | Adds unit coverage for modifier capitalization behavior and edge cases. |
| src/common/keybinding/index.js | Introduces capitalizeAccelerator() for canonical modifier casing. |
| src/renderer/prefComponents/keybindings/KeybindingConfigurator.js | Makes default-binding detection case-insensitive via isEqualAccelerator. |
| src/renderer/prefComponents/keybindings/key-input-dialog.vue | Normalizes captured accelerators before validation/display/save. |
| src/main/keyboard/shortcutHandler.js | Normalizes modifier casing when loading user keybindings from disk. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+24
to
+25
| * @param {string} accelerator | ||
| * @returns {string} |
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 #4123
getAcceleratorFromKeyboardEvent()which returns lowercase modifier names (e.g.ctrl+alt+1), but Electron requires properly capitalized modifiers (e.g.Ctrl+Alt+1) to register shortcuts correctly.capitalizeAccelerator()utility tosrc/common/keybinding/index.jsthat normalizes modifier casing against a canonical map (Ctrl, Alt, Shift, Cmd, Meta, Super, AltGr, Option, CommandOrControl, CmdOrCtrl, Command, Control).key-input-dialog.vueimmediately after capturing the accelerator, before saving._isDefaultBindinginKeybindingConfigurator.jsto useisEqualAccelerator(case-insensitive) instead of strict equality, so re-entering a default binding is correctly recognized.Test plan
capitalizeAccelerator()covering all modifier names, mixed case, empty/null input, and multi-modifier combinations (test/unit/specs/capitalize-accelerator.spec.js)Ctrl+Alt+1(notctrl+alt+1)🤖 Generated with Claude Code