From 2b0c9e87bfde25af162e76fae74f9544954a134d Mon Sep 17 00:00:00 2001 From: hackademix Date: Mon, 14 Mar 2022 21:29:10 +0100 Subject: [PATCH] Prompts can be closed by keyboard: Enter emulates the default button click, Escape the cancel action. --- src/ui/prompt.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ui/prompt.js b/src/ui/prompt.js index 5bf15dc..a96b7c8 100644 --- a/src/ui/prompt.js +++ b/src/ui/prompt.js @@ -115,6 +115,19 @@ b.addEventListener("click", buttonClicked); } + addEventListener("keydown", e => { + if (e.ctrlKey || e.metaKey || e.shiftKey) return; + switch(e.code) { + case "Escape": + window.close(); + return; + case "Enter": + let defButton = document.querySelector("#buttons button[type=submit]"); + if (defButton) defButton.click(); + return; + } + }); + let resize = async e => { if (!("windows" in browser)) { // tabbed (mobile?) - ensure buttons are visible