From 3e891c9c0be6873e036abb205230a6809ed94237 Mon Sep 17 00:00:00 2001 From: dtw-waleee Date: Mon, 14 Oct 2019 20:55:06 +0200 Subject: [PATCH] Fix keyboard layout issue with help-modal Some keyboard layouts produces a different ev.which value in firefox for ? than 191, eg. the Swedish QWERTY one produces 171. Chrome/chromium doesn't have this issue. --- lib/std/special/docs/main.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/std/special/docs/main.js b/lib/std/special/docs/main.js index 3650d46ec6..caa675167c 100644 --- a/lib/std/special/docs/main.js +++ b/lib/std/special/docs/main.js @@ -1210,9 +1210,20 @@ renderSearchCursor(); } + function getKeyValue(ev) { + if("key" in ev && typeof ev.key != "undefined") { + return ev.key + } + var code = ev.charCode || ev.keyCode; + if(code == 27) { + return "escape" + } + return String.fromCharCode(code) + } + function onWindowKeyDown(ev) { - switch (ev.which) { - case 27: + switch (getKeyValue(ev)) { + case "escape": if (ev.shiftKey || ev.ctrlKey || ev.altKey) return; if (!domHelpModal.classList.contains("hidden")) { domHelpModal.classList.add("hidden"); @@ -1220,7 +1231,7 @@ ev.stopPropagation(); } break; - case 83: + case "s": if (ev.shiftKey || ev.ctrlKey || ev.altKey) return; domSearch.focus(); domSearch.select(); @@ -1228,7 +1239,7 @@ ev.stopPropagation(); startAsyncSearch(); break; - case 191: + case "?": if (!ev.shiftKey || ev.ctrlKey || ev.altKey) return; ev.preventDefault(); ev.stopPropagation();