diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-12-14 07:10:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-14 07:10:43 +0000 |
commit | 097140ac1a3caf6e3c9980a757d4b52e6a76b789 (patch) | |
tree | c31cf29908f94e7f6792b063df4543d6f83b423c /script.js | |
parent | bda86f0fd9653657c146f7c1128f92771d16ad4e (diff) | |
parent | 778a30a95e216f9f7ce0126dbbdb1334afc3d796 (diff) | |
download | stable-diffusion-webui-gfx803-097140ac1a3caf6e3c9980a757d4b52e6a76b789.tar.gz stable-diffusion-webui-gfx803-097140ac1a3caf6e3c9980a757d4b52e6a76b789.tar.bz2 stable-diffusion-webui-gfx803-097140ac1a3caf6e3c9980a757d4b52e6a76b789.zip |
Merge branch 'dev' into master
Diffstat (limited to 'script.js')
-rw-r--r-- | script.js | 56 |
1 files changed, 45 insertions, 11 deletions
@@ -121,22 +121,56 @@ document.addEventListener("DOMContentLoaded", function() { }); /** - * Add a ctrl+enter as a shortcut to start a generation + * Add keyboard shortcuts: + * Ctrl+Enter to start/restart a generation + * Alt/Option+Enter to skip a generation + * Esc to interrupt a generation */ document.addEventListener('keydown', function(e) { - var 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) { - var button = get_uiCurrentTabContent().querySelector('button[id$=_generate]'); - if (button) { - button.click(); + 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) { + if (interruptButton.style.display === 'block') { + interruptButton.click(); + const callback = (mutationList) => { + for (const mutation of mutationList) { + if (mutation.type === 'attributes' && mutation.attributeName === 'style') { + if (interruptButton.style.display === 'none') { + generateButton.click(); + observer.disconnect(); + } + } + } + }; + const observer = new MutationObserver(callback); + observer.observe(interruptButton, {attributes: true}); + } else { + generateButton.click(); } e.preventDefault(); } + + if (isAltKey && isEnter) { + skipButton.click(); + e.preventDefault(); + } + + if (isEsc) { + const globalPopup = document.querySelector('.global-popup'); + const lightboxModal = document.querySelector('#lightboxModal'); + if (!globalPopup || globalPopup.style.display === 'none') { + if (document.activeElement === lightboxModal) return; + interruptButton.click(); + e.preventDefault(); + } + } }); /** |