Skip to content

Commit

Permalink
Merge pull request #13644 from XpucT/dev
Browse files Browse the repository at this point in the history
Start / Restart generation by Ctrl (Alt) + Enter
  • Loading branch information
AUTOMATIC1111 authored Oct 15, 2023
2 parents 2f6ea8b + d33cb2b commit 861cbd5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,20 @@ document.addEventListener("DOMContentLoaded", function() {
* Add a ctrl+enter as a shortcut to start 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 isModifierKey = e.metaKey || e.ctrlKey || e.altKey;

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

if (isEnter && isModifierKey) {
if (interruptButton.style.display === 'block') {
interruptButton.click();
setTimeout(function() {
generateButton.click();
}, 500);
} else {
generateButton.click();
}
e.preventDefault();
}
Expand Down

0 comments on commit 861cbd5

Please sign in to comment.