Skip to content

Commit

Permalink
Ignore keyboard events search box has focus (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jan 24, 2023
1 parent ef12d44 commit 0ae0712
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions static/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
let next = document.querySelector("a.next");
let next = document.querySelector('a.next');
let previous = document.querySelector('a.previous');

if (next) {
window.addEventListener("keydown", e => {
if (e.key == "ArrowRight") {
window.location = next.href;
}
});
}
window.addEventListener('keydown', e => {
if (document.activeElement.tagName == 'INPUT') {
return;
}

let previous = document.querySelector("a.previous");

if (previous) {
window.addEventListener("keydown", e => {
if (e.key == "ArrowLeft") {
window.location = previous.href;
}
});
}
switch (e.key) {
case 'ArrowRight':
if (next) {
window.location = next.href;
}
return;
case 'ArrowLeft':
if (previous) {
window.location = previous.href;
}
return;
}
});
2 changes: 1 addition & 1 deletion templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<a href=/rare.txt>rare.txt</a>
%% }
<form action=/search method=get>
<input type=text autocapitalize=off autocomplete=off autocorrect=off autofocus name=query spellcheck=false>
<input type=text autocapitalize=off autocomplete=off autocorrect=off name=query spellcheck=false>
<input type=submit value=Search>
</form>
</nav>
Expand Down

0 comments on commit 0ae0712

Please sign in to comment.