Allow result navigation w/ Tab and Shift+Tab

Closes #457
main
Ben Busby 2022-08-01 13:01:12 -06:00
parent 78614877f2
commit 839683b4e1
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
1 changed files with 50 additions and 36 deletions

View File

@ -1,8 +1,11 @@
(function () { (function () {
let searchBar, results; let searchBar, results;
let shift = false;
const keymap = { const keymap = {
ArrowUp: goUp, ArrowUp: goUp,
ArrowDown: goDown, ArrowDown: goDown,
ShiftTab: goUp,
Tab: goDown,
k: goUp, k: goUp,
j: goDown, j: goDown,
'/': focusSearch, '/': focusSearch,
@ -15,10 +18,21 @@
}); });
document.addEventListener('keydown', (e) => { document.addEventListener('keydown', (e) => {
if (e.key === 'Shift') {
shift = true;
}
if (e.target.tagName === 'INPUT') return true; if (e.target.tagName === 'INPUT') return true;
if (typeof keymap[e.key] === 'function') { if (typeof keymap[e.key] === 'function') {
e.preventDefault(); e.preventDefault();
keymap[e.key]();
keymap[`${shift && e.key == 'Tab' ? 'Shift' : ''}${e.key}`]();
}
});
document.addEventListener('keyup', (e) => {
if (e.key === 'Shift') {
shift = false;
} }
}); });