Skip to content

Commit 82880ce

Browse files
committed
Make unbind symmetrical with bind
1 parent dba0eb9 commit 82880ce

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

client/app/services/KeyboardShortcuts.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ const KeyboardShortcuts = {
3535

3636
bind: keymap => {
3737
each(keymap, (fn, key) => {
38-
// Resolve platformspecific modifiers and remove duplicates.
38+
// Resolve platform-specific modifiers and remove duplicates.
3939
const rawKeys = key
4040
.toLowerCase()
4141
.split(",")
4242
.map(trim);
43-
// Translate platformspecific modifiers and dedupe.
43+
// Translate platform-specific modifiers and dedupe.
4444
const transformed = rawKeys.map(k =>
4545
k.replace(/mod/g, modKey.toLowerCase())
4646
);
@@ -54,13 +54,18 @@ const KeyboardShortcuts = {
5454

5555
unbind: keymap => {
5656
each(keymap, (fn, key) => {
57-
const keys = key
57+
const rawKeys = key
5858
.toLowerCase()
5959
.split(",")
6060
.map(trim);
61-
each(keys, k => {
61+
// Apply the same transformation as in bind
62+
const transformed = rawKeys.map(k =>
63+
k.replace(/mod/g, modKey.toLowerCase())
64+
);
65+
const uniqueKeys = [...new Set(transformed)];
66+
each(uniqueKeys, k => {
6267
handlers[k] = without(handlers[k], fn);
63-
if (handlers[k].length === 0) {
68+
if (!handlers[k] || handlers[k].length === 0) {
6469
handlers[k] = undefined;
6570
Mousetrap.unbind(k);
6671
}

0 commit comments

Comments
 (0)