From 7670ecc63f3e30e320e2c4197eb7140c6196c168 Mon Sep 17 00:00:00 2001 From: cody Date: Wed, 7 Sep 2022 12:24:41 -0500 Subject: [PATCH] add more keyboard support on the web server (#391) add ability to submit prompts with the "enter" key add ability to cancel generations with the "escape" key --- static/dream_web/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/static/dream_web/index.js b/static/dream_web/index.js index 4d1fbe3778..2d2dce1452 100644 --- a/static/dream_web/index.js +++ b/static/dream_web/index.js @@ -154,6 +154,12 @@ async function generateSubmit(form) { } window.onload = () => { + document.querySelector("#prompt").addEventListener("keydown", (e) => { + if (e.key === "Enter" && !e.shiftKey) { + const form = e.target.form; + generateSubmit(form); + } + }); document.querySelector("#generate-form").addEventListener('submit', (e) => { e.preventDefault(); const form = e.target; @@ -180,6 +186,12 @@ window.onload = () => { console.error(e); }); }); + document.documentElement.addEventListener('keydown', (e) => { + if (e.key === "Escape") + fetch('/cancel').catch(err => { + console.error(err); + }); + }); if (!config.gfpgan_model_exists) { document.querySelector("#gfpgan").style.display = 'none';