From feba1d5eed3ef0098184f88376e7a7ec967dcbc4 Mon Sep 17 00:00:00 2001 From: "Paul W." Date: Fri, 24 Sep 2021 01:34:34 -0400 Subject: [PATCH] Fix arrow key scrolling and make it work on keydown instead of up There is an issue with the new key based nav system. When control elements lose their focus, there is no good way to bring it back. --- pages.json | 1 + scripts/fuzzy.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pages.json b/pages.json index 8fd9ae0..e0fa45d 100644 --- a/pages.json +++ b/pages.json @@ -6,5 +6,6 @@ {"title":"GitHub", "link": "https://github.com/lambdapaul"}, {"title":"GitLab", "link": "https://gitlab.com/lambdapaul"}, {"title":"Mastodon", "link": "https://mastodon.social/@lambdapaul"}, + {"title":"Matrix", "link": "https://matrix.to/#/@lambdapaul:matrix.org"}, {"title":"Keybase", "link": "https://keybase.io/lambdapaul"} ] \ No newline at end of file diff --git a/scripts/fuzzy.js b/scripts/fuzzy.js index 76054a1..89eb821 100644 --- a/scripts/fuzzy.js +++ b/scripts/fuzzy.js @@ -77,7 +77,7 @@ function fuzzyInit(pagesFileName) { } ); - document.body.addEventListener("keyup", (e) => { + document.body.addEventListener("keydown", (e) => { if (e.code === "ArrowDown" || e.code === "ArrowUp") { if (resultBlock.childNodes === null) return; @@ -90,6 +90,7 @@ function fuzzyInit(pagesFileName) { let currNode = document.activeElement; if (searchField === currNode) { + e.preventDefault(); if (e.code === "ArrowDown") resultNodes[0].focus(); else @@ -100,6 +101,7 @@ function fuzzyInit(pagesFileName) { if (Array.from(resultNodes).indexOf(currNode) < 0) return; + e.preventDefault(); if (e.code === "ArrowDown") if (currNode.nextElementSibling === null) searchField.focus();