Fix generate shortcut bug and add interrupt shortcut (#1408)
* Fix generate shortcut bug and add interrupt shortcut * Exit shortcut code early to avoid any issues
This commit is contained in:
parent
0a17fb8bc6
commit
f85c10338c
@ -125,18 +125,23 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
* Add a ctrl+enter as a shortcut to start a generation
|
* Add a ctrl+enter as a shortcut to start a generation
|
||||||
*/
|
*/
|
||||||
document.addEventListener('keydown', function(e) {
|
document.addEventListener('keydown', function(e) {
|
||||||
var handled = false;
|
const isModifierKey = (e.metaKey || e.ctrlKey || e.altKey);
|
||||||
if (e.key !== undefined) {
|
const isEnterKey = (e.key == "Enter" || e.keyCode == 13);
|
||||||
if ((e.key == "Enter" && (e.metaKey || e.ctrlKey || e.altKey))) handled = true;
|
|
||||||
} else if (e.keyCode !== undefined) {
|
if(isModifierKey && isEnterKey) {
|
||||||
if ((e.keyCode == 13 && (e.metaKey || e.ctrlKey || e.altKey))) handled = true;
|
const generateButton = gradioApp().querySelector('button:not(.hidden)[id=generate_button]');
|
||||||
}
|
if (generateButton) {
|
||||||
if (handled) {
|
generateButton.click();
|
||||||
var button = gradioApp().querySelector('button[id=generate_button]');
|
e.preventDefault();
|
||||||
if (button) {
|
return;
|
||||||
button.click();
|
}
|
||||||
|
|
||||||
|
const stopButton = gradioApp().querySelector('button:not(.hidden)[id=stop_button]')
|
||||||
|
if(stopButton) {
|
||||||
|
stopButton.click();
|
||||||
|
e.preventDefault();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user