ref: b5ccb0c9afb17a566b0be172737cac1147ea2d8b
parent: e79270368b709a7cceb593767b1d0ac9aa9a311f
author: Ben Harris <bjh21@bjh21.me.uk>
date: Wed Nov 23 17:27:54 EST 2022
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.
--- a/emccpre.js
+++ b/emccpre.js
@@ -458,7 +458,8 @@
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 @@
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();