|
|
@@ -8,30 +8,39 @@ export function routeChanged() {
|
|
|
}
|
|
|
|
|
|
function onKeyDown(e) {
|
|
|
- if (e.altKey || e.shiftKey || e.metaKey) return;
|
|
|
- if (e.key.length === 1 && !e.ctrlKey
|
|
|
- || e.code === 'KeyF' && e.ctrlKey) {
|
|
|
- document.querySelector('.filter-search input').focus();
|
|
|
+ if (e.altKey || e.shiftKey || e.metaKey) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const filterEl = document.querySelector('.filter-search input');
|
|
|
+ const activeEl = document.activeElement;
|
|
|
+ if (activeEl !== filterEl && activeEl?.matches?.('button, input, select, textarea')) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (e.key.length === 1 && !e.ctrlKey || e.code === 'KeyF' && e.ctrlKey) {
|
|
|
+ filterEl.focus();
|
|
|
+ if (e.ctrlKey) e.preventDefault();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (e.ctrlKey) {
|
|
|
return;
|
|
|
}
|
|
|
- if (e.ctrlKey) return;
|
|
|
let el = document.querySelector('.script.focused');
|
|
|
switch (e.key) {
|
|
|
- case 'Enter': {
|
|
|
- const activeEl = document.activeElement || document.body;
|
|
|
- if (el && !activeEl.matches('select, input:not([type="search"])')) {
|
|
|
+ case 'Enter':
|
|
|
+ if (el) {
|
|
|
e.preventDefault();
|
|
|
el.dispatchEvent(new Event('keydownEnter'));
|
|
|
}
|
|
|
break;
|
|
|
- }
|
|
|
case 'ArrowUp':
|
|
|
case 'ArrowDown': {
|
|
|
e.preventDefault();
|
|
|
const dir = e.key === 'ArrowUp' ? -1 : 1;
|
|
|
const all = document.querySelectorAll('.script:not([style*="display"])');
|
|
|
const numScripts = all.length;
|
|
|
- if (!numScripts) return;
|
|
|
+ if (!numScripts) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!el) {
|
|
|
all[dir > 0 ? 0 : numScripts - 1].classList.add('focused');
|
|
|
return;
|