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.
This commit is contained in:
Ben Harris
2022-11-23 22:27:54 +00:00
parent e79270368b
commit b5ccb0c9af

View File

@ -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();