From 8b42290939d6396f59dddb9d202bcda23f79ea0a Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 22 Jun 2023 12:15:59 +0100 Subject: [PATCH] static/tgal.js (keyevent): Discard key events with spurious modifiers. Allow shift with `^', `<' and `>' because they require that on common keyboard layouts (though not always), and because pressing shift gives a different result if it's not needed; forbid modifiers with cursor keys, space, and backspace. --- static/tgal.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/static/tgal.js b/static/tgal.js index 33f380d..6e96dc2 100644 --- a/static/tgal.js +++ b/static/tgal.js @@ -27,11 +27,13 @@ /* Handle keyboard interaction. */ addEventListener("keydown", function (ev) { var dir; - if (ev.key === " " || ev.key === "ArrowRight") dir = "next"; - else if (ev.key === "Backspace" || ev.key === "ArrowLeft") dir = "prev"; - else if (ev.key === "^") dir = "up"; + if (ev.altKey || ev.ctrlKey || ev.metaKey) return; else if (ev.key === "<") dir = "first"; else if (ev.key === ">") dir = "last"; + else if (ev.key === "^") dir = "up"; + else if (ev.shiftKey) return; + else if (ev.key === " " || ev.key === "ArrowRight") dir = "next"; + else if (ev.key === "Backspace" || ev.key === "ArrowLeft") dir = "prev"; else return; var elt = document.querySelector("link[rel=" + dir + "]"); if (!elt) return; -- 2.11.0