From d1db330010de31d48975bb3ec86e9e60d56ae9e9 Mon Sep 17 00:00:00 2001 From: Trung Ngo Date: Fri, 30 Sep 2022 15:31:00 -0500 Subject: [PATCH] ALT + return will submit prompt when it's in focus --- javascript/ui.js | 10 ++++++++++ modules/ui.py | 2 +- style.css | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/javascript/ui.js b/javascript/ui.js index 562d2552..6b52878d 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -186,10 +186,12 @@ onUiUpdate(function(){ if (!txt2img_textarea) { txt2img_textarea = gradioApp().querySelector("#txt2img_prompt > label > textarea"); txt2img_textarea?.addEventListener("input", () => update_token_counter("txt2img_token_button")); + txt2img_textarea?.addEventListener("keyup", (event) => submit_prompt(event, "txt2img_generate")); } if (!img2img_textarea) { img2img_textarea = gradioApp().querySelector("#img2img_prompt > label > textarea"); img2img_textarea?.addEventListener("input", () => update_token_counter("img2img_token_button")); + txt2img_textarea?.addEventListener("keyup", (event) => submit_prompt(event, "img2img_generate")); } }) @@ -197,6 +199,14 @@ let txt2img_textarea, img2img_textarea = undefined; let wait_time = 800 let token_timeout; +function submit_prompt(event, generate_button_id) { + if (event.altKey && event.keyCode === 13) { + event.preventDefault(); + gradioApp().getElementById(generate_button_id).click(); + return; + } +} + function update_token_counter(button_id) { if (token_timeout) clearTimeout(token_timeout); diff --git a/modules/ui.py b/modules/ui.py index 249b3eea..15572bb0 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -380,7 +380,7 @@ def create_toprow(is_img2img): with gr.Column(scale=1): with gr.Row(): interrupt = gr.Button('Interrupt', elem_id=f"{id_part}_interrupt") - submit = gr.Button('Generate', elem_id="generate", variant='primary') + submit = gr.Button('Generate', elem_id=f"{id_part}_generate", variant='primary') interrupt.click( fn=lambda: shared.state.interrupt(), diff --git a/style.css b/style.css index 9709c4ee..79d6bb0d 100644 --- a/style.css +++ b/style.css @@ -23,7 +23,7 @@ text-align: right; } -#generate{ +#txt2img_generate, #img2img_generate { min-height: 4.5em; }