mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
parent
9f4bff7f52
commit
751c06e437
4 changed files with 93 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
const {readFileSync} = require('fs');
|
const {readFileSync} = require('fs');
|
||||||
|
const {normalize} = require('../utils/keymaps-normalize');
|
||||||
const {defaultPlatformKeyPath} = require('./paths');
|
const {defaultPlatformKeyPath} = require('./paths');
|
||||||
|
|
||||||
const commands = {};
|
const commands = {};
|
||||||
|
|
@ -7,7 +8,7 @@ const keys = {};
|
||||||
const _setKeysForCommands = function (keymap) {
|
const _setKeysForCommands = function (keymap) {
|
||||||
for (const command in keymap) {
|
for (const command in keymap) {
|
||||||
if (command) {
|
if (command) {
|
||||||
commands[command] = keymap[command].toLowerCase();
|
commands[command] = normalize(keymap[command]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -35,8 +36,8 @@ const _extend = function (customsKeys) {
|
||||||
if (customsKeys) {
|
if (customsKeys) {
|
||||||
for (const command in customsKeys) {
|
for (const command in customsKeys) {
|
||||||
if (command) {
|
if (command) {
|
||||||
commands[command] = customsKeys[command];
|
commands[command] = normalize(customsKeys[command]);
|
||||||
keys[customsKeys[command]] = command;
|
keys[normalize(customsKeys[command])] = command;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
app/utils/keymaps-normalize.js
Normal file
23
app/utils/keymaps-normalize.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
const {getKeymaps} = require('../config/keymaps');
|
||||||
|
|
||||||
|
const normalize = keybinding => {
|
||||||
|
function sortAlphabetically(a, b) {
|
||||||
|
return a.localeCompare(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
return keybinding.toLowerCase().split('+').sort(sortAlphabetically).join('+');
|
||||||
|
};
|
||||||
|
|
||||||
|
const findCommandByKeys = (keys, commands) => {
|
||||||
|
return commands[normalize(keys)];
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCommand = keys => {
|
||||||
|
return findCommandByKeys(keys, getKeymaps().keys);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
normalize,
|
||||||
|
findCommandByKeys,
|
||||||
|
getCommand
|
||||||
|
};
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import {remote} from 'electron';
|
import {remote} from 'electron';
|
||||||
|
|
||||||
const {getKeymaps} = remote.require('./config');
|
const {getCommand} = remote.require('./utils/keymaps-normalize');
|
||||||
|
|
||||||
export default function returnKey(e) {
|
export default function returnKey(e) {
|
||||||
let keys = [];
|
let keys = [];
|
||||||
|
|
@ -30,5 +30,5 @@ export default function returnKey(e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
keys = keys.join('+');
|
keys = keys.join('+');
|
||||||
return getKeymaps().keys[keys.toLowerCase()];
|
return getCommand(keys);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
64
test/unit/keymaps-normalize.test.js
Normal file
64
test/unit/keymaps-normalize.test.js
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
import test from 'ava';
|
||||||
|
import {findCommandByKeys} from '../../app/utils/keymaps-normalize';
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue