-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Fix ctrl+enter resulting in duplicate triggers on non-Mac platforms. #7592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jakdaw
wants to merge
4
commits into
getredash:master
Choose a base branch
from
Jakdaw:fix-ctrl-enter-dupes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+17
−6
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
934c830
At present we bind both mod+enter and ctrl+enter to execute the curre…
Jakdaw dba0eb9
Second thoughts: let's not mess with alt+ - I don't think Mousetrap s…
Jakdaw 82880ce
Make unbind symmetrical with bind
Jakdaw 537845e
Mousetrap expects command+enter rather than cmd+enter. Additionally A…
Jakdaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { each, filter, map, toLower, toString, trim, upperFirst, without } from | |
| import Mousetrap from "mousetrap"; | ||
| import "mousetrap/plugins/global-bind/mousetrap-global-bind"; | ||
|
|
||
| const modKey = /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? "Cmd" : "Ctrl"; | ||
| const modKey = /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? "Command" : "Ctrl"; | ||
| const altKey = /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? "Option" : "Alt"; | ||
|
|
||
| export function humanReadableShortcut(shortcut, limit = Infinity) { | ||
|
|
@@ -35,11 +35,17 @@ const KeyboardShortcuts = { | |
|
|
||
| bind: keymap => { | ||
| each(keymap, (fn, key) => { | ||
| const keys = key | ||
| // Resolve platform-specific modifiers and remove duplicates. | ||
| const rawKeys = key | ||
| .toLowerCase() | ||
| .split(",") | ||
| .map(trim); | ||
| each(keys, k => { | ||
| // Translate platform-specific modifiers and dedupe. | ||
| const transformed = rawKeys.map(k => | ||
| k.replace(/mod/g, modKey.toLowerCase()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just feeling that it might be better not to depends on "modKey", as "modKey" is not for mapping but for human readable name. (For example, the name might be localized in the future.) How about just writing directly like below ? |
||
| ); | ||
| const uniqueKeys = [...new Set(transformed)]; | ||
| each(uniqueKeys, k => { | ||
| handlers[k] = [...without(handlers[k], fn), fn]; | ||
| Mousetrap.bindGlobal(k, onShortcut); | ||
| }); | ||
|
|
@@ -48,13 +54,18 @@ const KeyboardShortcuts = { | |
|
|
||
| unbind: keymap => { | ||
| each(keymap, (fn, key) => { | ||
| const keys = key | ||
| const rawKeys = key | ||
| .toLowerCase() | ||
| .split(",") | ||
| .map(trim); | ||
| each(keys, k => { | ||
| // Apply the same transformation as in bind | ||
| const transformed = rawKeys.map(k => | ||
| k.replace(/mod/g, modKey.toLowerCase()) | ||
| ); | ||
| const uniqueKeys = [...new Set(transformed)]; | ||
| each(uniqueKeys, k => { | ||
| handlers[k] = without(handlers[k], fn); | ||
| if (handlers[k].length === 0) { | ||
| if (!handlers[k] || handlers[k].length === 0) { | ||
| handlers[k] = undefined; | ||
| Mousetrap.unbind(k); | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: The
unbindfunction was not updated with the same key transformation logic. When bindingmod+enter, it gets stored asctrl+enterin handlers, but unbind will still look formod+enter, causing silent failures when trying to remove handlers.Prompt for AI agents
✅ Addressed in
82880ce