aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-11-23 22:27:54 +0000
committerBen Harris <bjh21@bjh21.me.uk>2022-11-23 22:27:54 +0000
commitb5ccb0c9afb17a566b0be172737cac1147ea2d8b (patch)
tree2a8d20345fa8996c9340c789638811d962019de6
parente79270368b709a7cceb593767b1d0ac9aa9a311f (diff)
downloadpuzzles-b5ccb0c9afb17a566b0be172737cac1147ea2d8b.zip
puzzles-b5ccb0c9afb17a566b0be172737cac1147ea2d8b.tar.gz
puzzles-b5ccb0c9afb17a566b0be172737cac1147ea2d8b.tar.bz2
puzzles-b5ccb0c9afb17a566b0be172737cac1147ea2d8b.tar.xz
js: Add actions for more keys in menus
I expect Escape to exit the menu, and SoftRight should do that as well for KaiOS. Backspace goes up one level through the menus, again because that's conventional on KaiOS and not too confusing elsewhere.
-rw-r--r--emccpre.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/emccpre.js b/emccpre.js
index cf01c51..e5cbb05 100644
--- a/emccpre.js
+++ b/emccpre.js
@@ -458,7 +458,8 @@ function initPuzzle() {
var cs = window.getComputedStyle(menu);
return cs.display == "flex" && cs.flexDirection == "row";
}
- if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Enter"]
+ if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Enter",
+ "Escape", "Backspace", "SoftRight"]
.includes(event.key))
return;
if (ishorizontal(thismenu)) {
@@ -494,11 +495,17 @@ function initPuzzle() {
else if (event.key == "ArrowLeft")
targetitem = parentitem_sideways ||
(parentitem_up && prevmenuitem(parentitem_up));
+ else if (event.key == "Backspace")
+ targetitem = parentitem;
}
if (targetitem)
targetitem.firstElementChild.focus();
else if (event.key == "Enter")
event.target.click();
+ else if (event.key == "Escape" || event.key == "SoftRight" ||
+ event.key == "Backspace")
+ // Leave the menu entirely.
+ onscreen_canvas.focus();
// Prevent default even if we didn't do anything, as long as this
// was an interesting key.
event.preventDefault();