-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const normalize = require('./normalize'); | ||
|
||
module.exports = (keys, commands) => { | ||
return commands[normalize(keys)]; | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const {getKeymaps} = require('../../config'); | ||
const findCommandByKeys = require('./find-command-by-keys'); | ||
|
||
module.exports = keys => { | ||
return findCommandByKeys(keys, getKeymaps().keys); | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// This function receives a keymap in any key order and returns | ||
// the same keymap alphatetically sorted by the clients locale. | ||
// eg.: cmd+alt+o -> alt+cmd+o | ||
// We do this in order to normalize what the user defined to what we | ||
// internally parse. By doing this, you can set your keymaps in any given order | ||
// eg.: alt+cmd+o, cmd+alt+o, o+alt+cmd, etc. #2195 | ||
module.exports = keybinding => { | ||
function sortAlphabetically(a, b) { | ||
return a.localeCompare(b); | ||
} | ||
|
||
return keybinding | ||
.toLowerCase() | ||
.split('+') | ||
.sort(sortAlphabetically) | ||
.join('+'); | ||
}; |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import test from 'ava'; | ||
import findCommandByKeys from '../../app/utils/keymaps/find-command-by-keys'; | ||
|
||
const expectedCommand = 'test-command'; | ||
const expectedLocalizedCommand = 'test-localized-command'; | ||
|
||
const commands = { | ||
'alt+p+shift': expectedCommand, | ||
'ç+cmd+ctrl': expectedLocalizedCommand | ||
}; | ||
|
||
test(`returns a command`, t => { | ||
t.is(findCommandByKeys('alt+shift+p', commands), expectedCommand); | ||
|
||
t.is(findCommandByKeys('shift+p+alt', commands), expectedCommand); | ||
|
||
t.is(findCommandByKeys('p+alt+shift', commands), expectedCommand); | ||
|
||
t.is(findCommandByKeys('alt+shift+P', commands), expectedCommand); | ||
|
||
t.is(findCommandByKeys('Shift+P+Alt', commands), expectedCommand); | ||
}); | ||
|
||
test(`returns a localized command`, t => { | ||
t.is(findCommandByKeys('cmd+ctrl+ç', commands), expectedLocalizedCommand); | ||
|
||
t.is(findCommandByKeys('ç+cmd+ctrl', commands), expectedLocalizedCommand); | ||
|
||
t.is(findCommandByKeys('ctrl+ç+cmd', commands), expectedLocalizedCommand); | ||
|
||
t.is(findCommandByKeys('ctrl+Ç+cmd', commands), expectedLocalizedCommand); | ||
|
||
t.is(findCommandByKeys('Cmd+Ctrl+Ç', commands), expectedLocalizedCommand); | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import test from 'ava'; | ||
import normalize from '../../app/utils/keymaps/normalize'; | ||
|
||
test(`is normalizing keymaps correctly`, t => { | ||
const notNormalized = 'cmd+alt+o'; | ||
const normalized = 'alt+cmd+o'; | ||
|
||
t.is(normalize(notNormalized), normalized); | ||
}); | ||
|
||
test(`is normalizing localized keymaps correctly`, t => { | ||
const notNormalized = 'cmd+alt+ç'; | ||
const normalized = 'alt+ç+cmd'; | ||
|
||
t.is(normalize(notNormalized), normalized); | ||
}); |