Skip to content

Commit

Permalink
Revert "Update extractOSSpecificKeys() to reduce redundancy"
Browse files Browse the repository at this point in the history
This reverts commit cd98595.
  • Loading branch information
tshino committed Dec 16, 2021
1 parent 8b6b3ad commit 4c3ea11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 10 additions & 1 deletion generator/gen_wrapper_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,34 @@ function extractOSSpecificKeys(keybinding) {
return clone;
};
const keybindings = [];
const restContext = [];
if ('mac' in keybinding && keybinding.key !== keybinding.mac) {
const mac = clone(keybinding);
mac.key = keybinding.mac;
mac.when = addWhenContext(keybinding.when, 'isMac');
keybindings.push(mac);
restContext.push('!isMac');
}
if ('linux' in keybinding && keybinding.key !== keybinding.linux) {
const linux = clone(keybinding);
linux.key = keybinding.linux;
linux.when = addWhenContext(keybinding.when, 'isLinux');
keybindings.push(linux);
restContext.push('!isLinux');
}
if ('win' in keybinding && keybinding.key !== keybinding.win) {
const win = clone(keybinding);
win.key = keybinding.win;
win.when = addWhenContext(keybinding.when, 'isWindows');
keybindings.push(win);
restContext.push('!isWindows');
}
keybindings.unshift(clone(keybinding));
const rest = clone(keybinding);
const restWhen = restContext.join(' && ');
if (restWhen) {
rest.when = addWhenContext(rest.when, restWhen);
}
keybindings.push(rest);
return keybindings;
}

Expand Down
18 changes: 9 additions & 9 deletions test/suite/gen_wrapper_util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ describe('gen_wrapper_util', () => {
it('should separate keybinding with "mac" key', () => {
const input = { key: 'key1', mac: 'key2', command: 'cmd1' };
const expected = [
{ key: 'key1', command: 'cmd1' },
{ key: 'key2', command: 'cmd1', when: 'isMac' }
{ key: 'key2', command: 'cmd1', when: 'isMac' },
{ key: 'key1', command: 'cmd1', when: '!isMac' }
];
const result = extractOSSpecificKeys(input);
assert.deepStrictEqual(result, expected);
Expand All @@ -105,8 +105,8 @@ describe('gen_wrapper_util', () => {
it('should separate keybinding with "linux" key', () => {
const input = { key: 'key1', linux: 'key2', command: 'cmd1' };
const expected = [
{ key: 'key1', command: 'cmd1' },
{ key: 'key2', command: 'cmd1', when: 'isLinux' }
{ key: 'key2', command: 'cmd1', when: 'isLinux' },
{ key: 'key1', command: 'cmd1', when: '!isLinux' }
];
const result = extractOSSpecificKeys(input);
assert.deepStrictEqual(result, expected);
Expand All @@ -122,8 +122,8 @@ describe('gen_wrapper_util', () => {
it('should separate keybinding with "win" key', () => {
const input = { key: 'key1', win: 'key2', command: 'cmd1' };
const expected = [
{ key: 'key1', command: 'cmd1' },
{ key: 'key2', command: 'cmd1', when: 'isWindows' }
{ key: 'key2', command: 'cmd1', when: 'isWindows' },
{ key: 'key1', command: 'cmd1', when: '!isWindows' }
];
const result = extractOSSpecificKeys(input);
assert.deepStrictEqual(result, expected);
Expand All @@ -144,12 +144,12 @@ describe('gen_wrapper_util', () => {
const result = extractOSSpecificKeys(input);
assert.deepStrictEqual(result, expected);
});
it('should separate keybinding with multiple OS specific keys', () => {
it('should separate keybinding with "win" and "mac" keys', () => {
const input = { key: 'key1', win: 'key2', mac: 'key3', command: 'cmd1' };
const expected = [
{ key: 'key1', command: 'cmd1' },
{ key: 'key3', command: 'cmd1', when: 'isMac' },
{ key: 'key2', command: 'cmd1', when: 'isWindows' }
{ key: 'key2', command: 'cmd1', when: 'isWindows' },
{ key: 'key1', command: 'cmd1', when: '!isMac && !isWindows' }
];
const result = extractOSSpecificKeys(input);
assert.deepStrictEqual(result, expected);
Expand Down

0 comments on commit 4c3ea11

Please sign in to comment.