From d5bf2314b3ee319585a1b2dc6a75cca04c8474f8 Mon Sep 17 00:00:00 2001 From: Jairo Correa Date: Sun, 26 Mar 2023 01:45:40 -0300 Subject: [PATCH] Mute nodes and shortcuts in README --- README.md | 7 ++++ web/scripts/app.js | 91 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ff03133..8eab7f48 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,13 @@ This ui will let you design and execute advanced stable diffusion pipelines usin Workflow examples can be found on the [Examples page](https://comfyanonymous.github.io/ComfyUI_examples/) +## Shortcuts +- **Ctrl + C** copy selected nodes +- **Ctrl + V** paste copied nodes +- **Ctrl + A** select all nodes +- **Ctrl + M** mute/unmute selected nodes +- **Delete** or **Backspace** delete selected nodes + # Installing ## Windows diff --git a/web/scripts/app.js b/web/scripts/app.js index cd7fb5d1..3b1f5450 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -417,6 +417,59 @@ class ComfyApp { }; } + /** + * Handle keypress + * + * Ctrl + M mute/unmute selected nodes + */ + #addProcessKeyHandler() { + const self = this; + const origProcessKey = LGraphCanvas.prototype.processKey; + LGraphCanvas.prototype.processKey = function(e) { + const res = origProcessKey.apply(this, arguments); + + if (res === false) { + return res; + } + + if (!this.graph) { + return; + } + + var block_default = false; + + if (e.target.localName == "input") { + return; + } + + if (e.type == "keydown") { + // Ctrl + M mute/unmute + if (e.keyCode == 77 && e.ctrlKey) { + if (this.selected_nodes) { + for (var i in this.selected_nodes) { + if (this.selected_nodes[i].mode === 2) { // never + this.selected_nodes[i].mode = 0; // always + } else { + this.selected_nodes[i].mode = 2; // never + } + } + } + block_default = true; + } + } + + this.graph.change(); + + if (block_default) { + e.preventDefault(); + e.stopImmediatePropagation(); + return false; + } + + return res; + }; + } + /** * Draws group header bar */ @@ -465,10 +518,11 @@ class ComfyApp { * Draws node highlights (executing, drag drop) and progress bar */ #addDrawNodeHandler() { - const orig = LGraphCanvas.prototype.drawNodeShape; + const origDrawNodeShape = LGraphCanvas.prototype.drawNodeShape; const self = this; + LGraphCanvas.prototype.drawNodeShape = function (node, ctx, size, fgcolor, bgcolor, selected, mouse_over) { - const res = orig.apply(this, arguments); + const res = origDrawNodeShape.apply(this, arguments); let color = null; if (node.id === +self.runningNodeId) { @@ -517,6 +571,21 @@ class ComfyApp { return res; }; + + const origDrawNode = LGraphCanvas.prototype.drawNode; + LGraphCanvas.prototype.drawNode = function (node, ctx) { + var editor_alpha = this.editor_alpha; + + if (node.mode === 2) { // never + this.editor_alpha = 0.4; + } + + const res = origDrawNode.apply(this, arguments); + + this.editor_alpha = editor_alpha; + + return res; + }; } /** @@ -588,6 +657,7 @@ class ComfyApp { document.body.prepend(canvasEl); this.#addProcessMouseHandler(); + this.#addProcessKeyHandler(); this.graph = new LGraph(); const canvas = (this.canvas = new LGraphCanvas(canvasEl, this.graph)); @@ -777,6 +847,11 @@ class ComfyApp { continue; } + if (node.mode === 2) { + // Don't serialize muted nodes + continue; + } + const inputs = {}; const widgets = node.widgets; @@ -816,6 +891,18 @@ class ComfyApp { }; } + // Remove inputs connected to removed nodes + + for (const o in output) { + for (const i in output[o].inputs) { + if (Array.isArray(output[o].inputs[i]) + && output[o].inputs[i].length === 2 + && !output[output[o].inputs[i][0]]) { + delete output[o].inputs[i]; + } + } + } + return { workflow, output }; }