From 532a3e1e9d93c1688ee13dd9fd3bfa4e2c106763 Mon Sep 17 00:00:00 2001 From: EllangoK Date: Thu, 13 Apr 2023 00:47:53 -0400 Subject: [PATCH] adds keybinds that interact w/ comfy menu --- web/extensions/core/keybinds.js | 31 +++++++++++++++++++++++++++++++ web/scripts/ui.js | 9 +++++---- 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 web/extensions/core/keybinds.js diff --git a/web/extensions/core/keybinds.js b/web/extensions/core/keybinds.js new file mode 100644 index 000000000..fba565961 --- /dev/null +++ b/web/extensions/core/keybinds.js @@ -0,0 +1,31 @@ +import { app } from "/scripts/app.js"; + +const id = "Comfy.Keybinds"; +app.registerExtension({ + name: id, + init() { + const keybindListener = function(event) { + const target = event.composedPath()[0]; + + if (target.tagName === "INPUT" || target.tagName === "TEXTAREA") { + return; + } + + const keyToButtonIdMap = { + "s": "save-button", + "l": "load-button", + "r": "refresh-button", + "c": "clear-button", + "d": "load-default-button" + }; + + const buttonId = keyToButtonIdMap[event.key]; + if (buttonId) { + const button = document.querySelector(`#${buttonId}`); + button.dispatchEvent(new Event("click")); + } + } + + document.addEventListener("keyup", keybindListener); + } +}); \ No newline at end of file diff --git a/web/scripts/ui.js b/web/scripts/ui.js index 09861c440..c8f7e94ce 100644 --- a/web/scripts/ui.js +++ b/web/scripts/ui.js @@ -517,6 +517,7 @@ export class ComfyUI { this.queue.element, this.history.element, $el("button", { + id: "save-button", textContent: "Save", onclick: () => { const json = JSON.stringify(app.graph.serialize(), null, 2); // convert the data to a JSON string @@ -535,15 +536,15 @@ export class ComfyUI { }, 0); }, }), - $el("button", { textContent: "Load", onclick: () => fileInput.click() }), - $el("button", { textContent: "Refresh", onclick: () => app.refreshComboInNodes() }), - $el("button", { textContent: "Clear", onclick: () => { + $el("button", { id: "load-button", textContent: "Load", onclick: () => fileInput.click() }), + $el("button", { id: "refresh-button", textContent: "Refresh", onclick: () => app.refreshComboInNodes() }), + $el("button", { id: "clear-button", textContent: "Clear", onclick: () => { if (!confirmClear.value || confirm("Clear workflow?")) { app.clean(); app.graph.clear(); } }}), - $el("button", { textContent: "Load Default", onclick: () => { + $el("button", { id: "load-default-button", textContent: "Load Default", onclick: () => { if (!confirmClear.value || confirm("Load default workflow?")) { app.loadGraphData() }