fix #86 keyboard walk up/dow respects filters

This commit is contained in:
Koen Lageveen 2020-10-09 20:32:03 +02:00 committed by Koen Lageveen
parent f8c5242a41
commit 50d031fe98
1 changed files with 20 additions and 15 deletions

View File

@ -232,21 +232,26 @@ function toggleFavorite(alias) {
return false;
}
function nextFont() {
function walk(direction) {
var activeEntry = document.querySelector('.entry.active');
var next = activeEntry.nextSibling;
if (next && next.matches('.entry')) {
next.querySelector('a').click();
next.scrollIntoView();
}
}
var target = null;
var next = direction === 'up' ? activeEntry.previousSibling : activeEntry.nextSibling;
function previousFont() {
var activeEntry = document.querySelector('.entry.active');
var next = activeEntry.previousSibling;
if (next && next.matches('.entry')) {
next.querySelector('a').click();
next.scrollIntoView();
while (target === null) {
if (next) {
if (next.matches('.entry:not(.filtered-out)')) {
target = next;
} else {
next = direction === 'up' ? next.previousSibling : next.nextSibling;
}
} else {
target = false;
}
}
if (target) {
target.querySelector('a').click();
target.scrollIntoView();
}
}
@ -345,12 +350,12 @@ $(document).ready(function() {
if (event.key === 'ArrowUp') {
event.preventDefault();
event.stopPropagation();
previousFont();
walk('up');
return;
} else if (event.key === 'ArrowDown') {
event.preventDefault();
event.stopPropagation();
nextFont();
walk('down');
return;
}
}