Commit f00eaa4d authored by Khachatur Avanesian's avatar Khachatur Avanesian Committed by GitHub

Start / Restart generation by Ctrl (Alt) + Enter

Add ability to interrupt current generation and start generation again by Ctrl (Alt) + Enter
parent d4255506
...@@ -121,23 +121,25 @@ document.addEventListener("DOMContentLoaded", function() { ...@@ -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) { document.addEventListener('keydown', (e) => {
var handled = false; const isEnter = e.key === 'Enter' || e.keyCode === 13
if (e.key !== undefined) { const isModifierKey = e.metaKey || e.ctrlKey || e.altKey
if ((e.key == "Enter" && (e.metaKey || e.ctrlKey || e.altKey))) handled = true;
} else if (e.keyCode !== undefined) { const interruptButton = get_uiCurrentTabContent().querySelector('button[id$=_interrupt]')
if ((e.keyCode == 13 && (e.metaKey || e.ctrlKey || e.altKey))) handled = true; 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) { e.preventDefault()
var button = get_uiCurrentTabContent().querySelector('button[id$=_generate]');
if (button) {
button.click();
} }
e.preventDefault(); })
}
});
/** /**
* checks that a UI element is not in another hidden element or tab content * checks that a UI element is not in another hidden element or tab content
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment