Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Uppercase all key combinations for consistent serialization
Browse files Browse the repository at this point in the history
Issue #1283
  • Loading branch information
pablosichert committed Nov 16, 2017
1 parent 5aadac0 commit 6295286
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
14 changes: 10 additions & 4 deletions src/components/Shortcuts/blacklist.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const mods = [
'ctrl', // Windows, Linux
'cmd' // macOS
'Control', // Windows, Linux
'Meta' // macOS
];

export default Object.assign(...mods.map(mod => ({
export default Object.entries(Object.assign(...mods.map(mod => ({
[`${mod}+l`]: 'Focus address bar',
[`${mod}+t`]: 'New tab',
[`${mod}+w`]: 'Close tab'
})));
})))).reduce((blacklist, pair) => {
const [key, value] = pair;

blacklist[key.toUpperCase()] = value;

return blacklist;
}, {});
4 changes: 3 additions & 1 deletion src/components/Shortcuts/generateHotkeys.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export default ({ keymap = {}, blacklist = {} } = {}) => {
const hotkeys = {};

for (const [name, hotkey] of Object.entries(keymap)) {
for (const [name, _hotkey] of Object.entries(keymap)) {
const hotkey = _hotkey.toUpperCase();

if (hotkey in blacklist) {
const reason = blacklist[hotkey];

Expand Down
16 changes: 8 additions & 8 deletions src/components/Shortcuts/generateHotkeys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe('generateHotkeys', () => {

it('should transform a key map to a map of hotkeys', () => {
const keymap = {
COMBO_A: 'ctrl+a',
COMBO_B: 'ctrl+b'
COMBO_A: 'CONTROL+A',
COMBO_B: 'CONTROL+B'
};

const hotkeys = generateHotkeys({ keymap });

expect(hotkeys).to.deep.equal({
'ctrl+a': [],
'ctrl+b': []
'CONTROL+A': [],
'CONTROL+B': []
});
});

Expand All @@ -33,8 +33,8 @@ describe('generateHotkeys', () => {

try {
const keymap = {
COMBO_1: 'ctrl+a',
COMBO_2: 'ctrl+a'
COMBO_1: 'CONTROL+A',
COMBO_2: 'CONTROL+A'
};

generateHotkeys({ keymap });
Expand All @@ -52,11 +52,11 @@ describe('generateHotkeys', () => {

try {
const blacklist = {
'ctrl+w': 'Close tab'
'CONTROL+W': 'Close tab'
};

const keymap = {
COMBO_1: 'ctrl+w'
COMBO_1: 'CONTROL+W'
};

generateHotkeys({ keymap, blacklist });
Expand Down
2 changes: 1 addition & 1 deletion src/components/Shortcuts/keymap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mod = 'ctrl';
const mod = 'Control';

export default {
/* Global context */
Expand Down

0 comments on commit 6295286

Please sign in to comment.