aboutsummaryrefslogtreecommitdiff
path: root/script.js
diff options
context:
space:
mode:
authorkaalibro <konstantin.adamovich@gmail.com>2023-12-09 21:04:45 +0600
committerkaalibro <konstantin.adamovich@gmail.com>2023-12-09 21:04:45 +0600
commit9c201550ddae0b33367adfb99bcbb57ba9b207a9 (patch)
treedb605a00a69cc6048606a3f6f88434c0c1ae2e65 /script.js
parentf92d61497a426a19818625c3ccdaae9beeb82b31 (diff)
Add keyboard shortcuts for generation
(Removed Alt+Enter) Ctrl+Enter to start/restart generation (New) Alt/Option+Enter to skip generation (New) Ctrl+Alt/Option+Enter to interrupt generation
Diffstat (limited to 'script.js')
-rw-r--r--script.js23
1 files changed, 19 insertions, 4 deletions
diff --git a/script.js b/script.js
index c0e678ea..69598f45 100644
--- a/script.js
+++ b/script.js
@@ -121,16 +121,21 @@ 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
+ * Alt/Option+Ctrl+Enter to interrupt a generation
*/
document.addEventListener('keydown', function(e) {
const isEnter = e.key === 'Enter' || e.keyCode === 13;
- const isModifierKey = e.metaKey || e.ctrlKey || e.altKey;
+ const isCtrlKey = e.metaKey || e.ctrlKey;
+ const isAltKey = e.altKey;
- const interruptButton = get_uiCurrentTabContent().querySelector('button[id$=_interrupt]');
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 (isEnter && isModifierKey) {
+ if (isCtrlKey && isEnter && !isAltKey) {
if (interruptButton.style.display === 'block') {
interruptButton.click();
const callback = (mutationList) => {
@@ -150,6 +155,16 @@ document.addEventListener('keydown', function(e) {
}
e.preventDefault();
}
+
+ if (isAltKey && isEnter && !isCtrlKey) {
+ skipButton.click();
+ e.preventDefault();
+ }
+
+ if (isAltKey && isCtrlKey && isEnter) {
+ interruptButton.click();
+ e.preventDefault();
+ }
});
/**