Start / Restart generation by Ctrl (Alt) + Enter

Add ability to interrupt current generation and start generation again by Ctrl (Alt) + Enter
This commit is contained in:
Khachatur Avanesian 2023-10-15 02:34:03 +03:00 committed by GitHub
parent d4255506ff
commit f00eaa4d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 165 additions and 163 deletions

View File

@ -121,23 +121,25 @@ document.addEventListener("DOMContentLoaded", function() {
});
/**
* Add a ctrl+enter as a shortcut to start a generation
* Add a Ctrl (Alt) + Enter as a shortcut to start / restart 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;
document.addEventListener('keydown', (e) => {
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(() => generateButton.click(), 500)
} else {
generateButton.click()
}
if (handled) {
var button = get_uiCurrentTabContent().querySelector('button[id$=_generate]');
if (button) {
button.click();
e.preventDefault()
}
e.preventDefault();
}
});
})
/**
* checks that a UI element is not in another hidden element or tab content