adds keybinds that interact w/ comfy menu

This commit is contained in:
EllangoK 2023-04-13 00:47:53 -04:00
parent 3f52e7cbb1
commit 532a3e1e9d
2 changed files with 36 additions and 4 deletions

View File

@ -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);
}
});

View File

@ -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()
}