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
This commit is contained in:
cody 2022-09-07 12:24:41 -05:00 committed by GitHub
parent dd2aedacaf
commit 7670ecc63f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -154,6 +154,12 @@ async function generateSubmit(form) {
} }
window.onload = () => { 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) => { document.querySelector("#generate-form").addEventListener('submit', (e) => {
e.preventDefault(); e.preventDefault();
const form = e.target; const form = e.target;
@ -180,6 +186,12 @@ window.onload = () => {
console.error(e); console.error(e);
}); });
}); });
document.documentElement.addEventListener('keydown', (e) => {
if (e.key === "Escape")
fetch('/cancel').catch(err => {
console.error(err);
});
});
if (!config.gfpgan_model_exists) { if (!config.gfpgan_model_exists) {
document.querySelector("#gfpgan").style.display = 'none'; document.querySelector("#gfpgan").style.display = 'none';