use Event#key for hotkey recognition in manager and popup

should help #286
This commit is contained in:
tophf 2017-12-07 02:11:50 +03:00
parent 119a3803ec
commit b96cee1012
2 changed files with 13 additions and 12 deletions

View File

@ -75,9 +75,9 @@ onDOMready().then(() => {
event.target.matches('[type="text"], [type="search"]')) {
return;
}
const k = event.which;
const {which: k, key} = event;
// focus search field on "/" key
if (k === 191 && !event.shiftKey) {
if (key === '/' || !key && k === 191 && !event.shiftKey) {
event.preventDefault();
$('#search').focus();
return;

View File

@ -34,23 +34,24 @@ var hotkeys = (() => {
return;
}
let entry;
const k = event.which;
if (k >= 48 && k <= 57 || k >= 96 && k <= 105) {
const {which: k, key} = event;
if (key ? key >= '0' && key <= '9' : k >= 48 && k <= 57 || k >= 96 && k <= 105) {
// 0-9, numpad 0-9
entry = installed.children[k === 48 || k === 96 ? 9 : k - (k > 96 ? 97 : 49)];
} else if (k >= 65 && k <= 90) {
// a-z
const letter = new RegExp('^\\x' + k.toString(16), 'i');
entry = [...installed.children].find(entry => letter.test(entry.textContent));
} else if (k === 192 || k === 106) {
const i = key === '0' ? 9 : key ? Number(key) - 1 : k === 48 || k === 96 ? 9 : k - (k > 96 ? 97 : 49);
entry = installed.children[i];
} else if (key ? key === '`' || key === '*' && !event.shiftKey : k === 192 || k === 106) {
// backtick ` and numpad *
invertTogglables();
} else if (k === 109) {
} else if (key ? key === '-' : k === 109) {
// numpad -
toggleState(installed.children, 'enabled', false);
} else if (k === 107) {
} else if (key ? key === '+' : k === 107) {
// numpad +
toggleState(installed.children, 'disabled', true);
} else if (key ? key.length === 1 : k >= 65 && k <= 90) {
// any single character
const letter = new RegExp(key ? '^' + key : '^\\x' + k.toString(16), 'i');
entry = [...installed.children].find(entry => letter.test(entry.textContent));
}
if (!entry) {
return;