diff --git a/web/extensions/core/keybinds.js b/web/extensions/core/keybinds.js index e3284f905..ceca00ff1 100644 --- a/web/extensions/core/keybinds.js +++ b/web/extensions/core/keybinds.js @@ -11,13 +11,15 @@ app.registerExtension({ return; } + if (event.ctrlKey || event.altKey || event.metaKey) { + return; + } + const keyToButtonIdMap = { "Enter": "queue-button", "f": "queue-front-button", "q": "view-queue-button", "h": "view-history-button", - "s": "save-button", - "l": "load-button", "r": "refresh-button", "c": "clear-button", "d": "load-default-button", diff --git a/web/scripts/app.js b/web/scripts/app.js index 2f5e73220..bf0988353 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -691,11 +691,40 @@ class ComfyApp { #addKeyboardHandler() { window.addEventListener("keydown", (e) => { this.shiftDown = e.shiftKey; + const modifierPressed = e.ctrlKey || e.metaKey; // Queue prompt using ctrl or command + enter - if ((e.ctrlKey || e.metaKey) && (e.key === "Enter" || e.keyCode === 13 || e.keyCode === 10)) { + if (modifierPressed && (e.key === "Enter" || e.keyCode === 13 || e.keyCode === 10)) { this.queuePrompt(e.shiftKey ? -1 : 0); } + + // Save workflow using ctrl or command + s + if (modifierPressed && (e.key === "s" || e.keyCode === 83)) { + e.preventDefault(); + + const json = JSON.stringify(app.graph.serialize(), null, 2); // convert the data to a JSON string + const blob = new Blob([json], { type: "application/json" }); + const url = URL.createObjectURL(blob); + const a = $el("a", { + href: url, + download: "workflow.json", + style: { display: "none" }, + parent: document.body, + }); + a.click(); + setTimeout(function () { + a.remove(); + window.URL.revokeObjectURL(url); + }, 0); + } + + // Load workflow using ctrl or command + o + if (modifierPressed && (e.key === "o" || e.keyCode === 79)) { + e.preventDefault(); + + const fileInput = document.querySelector("#comfy-file-input"); + fileInput.click() + } }); window.addEventListener("keyup", (e) => { this.shiftDown = e.shiftKey; diff --git a/web/scripts/ui.js b/web/scripts/ui.js index e668b3798..83ad0fbab 100644 --- a/web/scripts/ui.js +++ b/web/scripts/ui.js @@ -432,6 +432,7 @@ export class ComfyUI { }); const fileInput = $el("input", { + id: "comfy-file-input", type: "file", accept: ".json,image/png", style: { display: "none" },