From b3d75d2c7d2456196bfd7ea80b4b9d35335a61f5 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 30 Oct 2024 09:44:07 -0400 Subject: [PATCH] hotkeys Signed-off-by: Vladimir Mandic --- javascript/script.js | 24 ++++++++++++++---------- wiki | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/javascript/script.js b/javascript/script.js index 6f52f4a3d..104567dd7 100644 --- a/javascript/script.js +++ b/javascript/script.js @@ -133,19 +133,23 @@ document.addEventListener('DOMContentLoaded', () => { }); /** - * Add a ctrl+enter as a shortcut to start a generation + * Add a listener to the document for keydown events */ document.addEventListener('keydown', (e) => { - let handled = false; - if (e.key !== undefined) { - if ((e.key === 'Enter' && (e.metaKey || e.ctrlKey || e.altKey))) handled = true; - } else if (e.keyCode !== undefined) { - if ((e.keyCode === 13 && (e.metaKey || e.ctrlKey || e.altKey))) handled = true; - } - if (handled) { - const button = getUICurrentTabContent().querySelector('button[id$=_generate]'); - if (button) button.click(); + let elem; + if (e.key === 'Escape') elem = getUICurrentTabContent().querySelector('button[id$=_interrupt]'); + if (e.key === 'Enter' && e.ctrlKey) elem = getUICurrentTabContent().querySelector('button[id$=_generate]'); + if (e.key === 'Backspace' && e.ctrlKey) elem = getUICurrentTabContent().querySelector('button[id$=_reprocess]'); + if (e.key === ' ' && e.ctrlKey) elem = getUICurrentTabContent().querySelector('button[id$=_extra_networks_btn]'); + if (e.key === 's' && e.ctrlKey) elem = getUICurrentTabContent().querySelector('button[id^=save_]'); + if (e.key === 'Insert' && e.ctrlKey) elem = getUICurrentTabContent().querySelector('button[id^=save_]'); + if (e.key === 'Delete' && e.ctrlKey) elem = getUICurrentTabContent().querySelector('button[id^=delete_]'); + // if (e.key === 'm' && e.ctrlKey) elem = gradioApp().getElementById('setting_sd_model_checkpoint'); + if (elem) { e.preventDefault(); + log('hotkey', { key: e.key, meta: e.metaKey, ctrl: e.ctrlKey, alt: e.altKey }, elem?.id, elem.nodeName); + if (elem.nodeName === 'BUTTON') elem.click(); + else elem.focus(); } }); diff --git a/wiki b/wiki index 4360bc7fc..f5a169ff9 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 4360bc7fcfd5dc301b825a6c5dcf4274c8eba983 +Subproject commit f5a169ff9e30f9157feec9d3e142d80d7e2ca31a