use Event#key for hotkey recognition in manager and popup
should help #286
This commit is contained in:
parent
119a3803ec
commit
b96cee1012
|
@ -75,9 +75,9 @@ onDOMready().then(() => {
|
||||||
event.target.matches('[type="text"], [type="search"]')) {
|
event.target.matches('[type="text"], [type="search"]')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const k = event.which;
|
const {which: k, key} = event;
|
||||||
// focus search field on "/" key
|
// focus search field on "/" key
|
||||||
if (k === 191 && !event.shiftKey) {
|
if (key === '/' || !key && k === 191 && !event.shiftKey) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
$('#search').focus();
|
$('#search').focus();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -34,23 +34,24 @@ var hotkeys = (() => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let entry;
|
let entry;
|
||||||
const k = event.which;
|
const {which: k, key} = event;
|
||||||
if (k >= 48 && k <= 57 || k >= 96 && k <= 105) {
|
if (key ? key >= '0' && key <= '9' : k >= 48 && k <= 57 || k >= 96 && k <= 105) {
|
||||||
// 0-9, numpad 0-9
|
// 0-9, numpad 0-9
|
||||||
entry = installed.children[k === 48 || k === 96 ? 9 : k - (k > 96 ? 97 : 49)];
|
const i = key === '0' ? 9 : key ? Number(key) - 1 : k === 48 || k === 96 ? 9 : k - (k > 96 ? 97 : 49);
|
||||||
} else if (k >= 65 && k <= 90) {
|
entry = installed.children[i];
|
||||||
// a-z
|
} else if (key ? key === '`' || key === '*' && !event.shiftKey : k === 192 || k === 106) {
|
||||||
const letter = new RegExp('^\\x' + k.toString(16), 'i');
|
|
||||||
entry = [...installed.children].find(entry => letter.test(entry.textContent));
|
|
||||||
} else if (k === 192 || k === 106) {
|
|
||||||
// backtick ` and numpad *
|
// backtick ` and numpad *
|
||||||
invertTogglables();
|
invertTogglables();
|
||||||
} else if (k === 109) {
|
} else if (key ? key === '-' : k === 109) {
|
||||||
// numpad -
|
// numpad -
|
||||||
toggleState(installed.children, 'enabled', false);
|
toggleState(installed.children, 'enabled', false);
|
||||||
} else if (k === 107) {
|
} else if (key ? key === '+' : k === 107) {
|
||||||
// numpad +
|
// numpad +
|
||||||
toggleState(installed.children, 'disabled', true);
|
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) {
|
if (!entry) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user