Skip to content

Commit

Permalink
Replace Ctrl+Alt+Enter with Esc
Browse files Browse the repository at this point in the history
  • Loading branch information
kaalibro committed Dec 10, 2023
1 parent 9c20155 commit 1d42bab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions modules/ui_toprow.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def create_inline_toprow_image(self):
def create_prompts(self):
with gr.Column(elem_id=f"{self.id_part}_prompt_container", elem_classes=["prompt-container-compact"] if self.is_compact else [], scale=6):
with gr.Row(elem_id=f"{self.id_part}_prompt_row", elem_classes=["prompt-row"]):
self.prompt = gr.Textbox(label="Prompt", elem_id=f"{self.id_part}_prompt", show_label=False, lines=3, placeholder="Prompt\n(Press Ctrl+Enter to generate, Alt+Enter to skip, Ctrl+Alt+Enter to interrupt)", elem_classes=["prompt"])
self.prompt = gr.Textbox(label="Prompt", elem_id=f"{self.id_part}_prompt", show_label=False, lines=3, placeholder="Prompt\n(Press Ctrl+Enter to generate, Alt+Enter to skip, Esc to interrupt)", elem_classes=["prompt"])
self.prompt_img = gr.File(label="", elem_id=f"{self.id_part}_prompt_image", file_count="single", type="binary", visible=False)

with gr.Row(elem_id=f"{self.id_part}_neg_prompt_row", elem_classes=["prompt-row"]):
self.negative_prompt = gr.Textbox(label="Negative prompt", elem_id=f"{self.id_part}_neg_prompt", show_label=False, lines=3, placeholder="Negative prompt\n(Press Ctrl+Enter to generate, Alt+Enter to skip, Ctrl+Alt+Enter to interrupt)", elem_classes=["prompt"])
self.negative_prompt = gr.Textbox(label="Negative prompt", elem_id=f"{self.id_part}_neg_prompt", show_label=False, lines=3, placeholder="Negative prompt\n(Press Ctrl+Enter to generate, Alt+Enter to skip, Esc to interrupt)", elem_classes=["prompt"])

self.prompt_img.change(
fn=modules.images.image_data,
Expand Down
17 changes: 11 additions & 6 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,19 @@ document.addEventListener("DOMContentLoaded", function() {
* Add keyboard shortcuts:
* Ctrl+Enter to start/restart a generation
* Alt/Option+Enter to skip a generation
* Alt/Option+Ctrl+Enter to interrupt a generation
* Esc to interrupt a generation
*/
document.addEventListener('keydown', function(e) {
const isEnter = e.key === 'Enter' || e.keyCode === 13;
const isCtrlKey = e.metaKey || e.ctrlKey;
const isAltKey = e.altKey;
const isEsc = e.key === 'Escape';

const generateButton = get_uiCurrentTabContent().querySelector('button[id$=_generate]');
const interruptButton = get_uiCurrentTabContent().querySelector('button[id$=_interrupt]');
const skipButton = get_uiCurrentTabContent().querySelector('button[id$=_skip]');

if (isCtrlKey && isEnter && !isAltKey) {
if (isCtrlKey && isEnter) {
if (interruptButton.style.display === 'block') {
interruptButton.click();
const callback = (mutationList) => {
Expand All @@ -156,14 +157,18 @@ document.addEventListener('keydown', function(e) {
e.preventDefault();
}

if (isAltKey && isEnter && !isCtrlKey) {
if (isAltKey && isEnter) {
skipButton.click();
e.preventDefault();
}

if (isAltKey && isCtrlKey && isEnter) {
interruptButton.click();
e.preventDefault();
if (isEsc) {
if (!globalPopup || globalPopup.style.display === "none") {
interruptButton.click();
e.preventDefault();
} else {
closePopup();
}
}
});

Expand Down

0 comments on commit 1d42bab

Please sign in to comment.