Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Prevent exactly overlapping nodes Throttle double click

pythongosssssd6830b958c1f
diff --git a/web/extensions/core/widgetInputs.js b/web/extensions/core/widgetInputs.js
index ad8bcdf02..5e6013471 100644
--- a/web/extensions/core/widgetInputs.js
+++ b/web/extensions/core/widgetInputs.js
@@ -139,17 +139,41 @@ app.registerExtension({
return r;
};
+ function isNodeAtPos(pos) {
+ for (const n of app.graph._nodes) {
+ if (n.pos[0] === pos[0] && n.pos[1] === pos[1]) {
+ return true;
+ }
+ }
+ return false;
+ }
+
// Double click a widget input to automatically attach a primitive
const origOnInputDblClick = nodeType.prototype.onInputDblClick;
+ const ignoreDblClick = Symbol();
nodeType.prototype.onInputDblClick = function (slot) {
const r = origOnInputDblClick ? origOnInputDblClick.apply(this, arguments) : undefined;
- if (this.inputs[slot].widget) {
+ const input = this.inputs[slot];
+ if (input.widget && !input[ignoreDblClick]) {
const node = LiteGraph.createNode("PrimitiveNode");
app.graph.add(node);
- node.pos = [this.pos[0] - node.size[0] - 30, this.pos[1]];
+
+ // Calculate a position that wont directly overlap another node
+ const pos = [this.pos[0] - node.size[0] - 30, this.pos[1]];
+ while (isNodeAtPos(pos)) {
+ pos[1] += LiteGraph.NODE_TITLE_HEIGHT;
+ }
+
+ node.pos = pos;
node.connect(0, this, slot);
- node.title = this.inputs[slot].name;
+ node.title = input.name;
+
+ // Prevent adding duplicates due to triple clicking
+ input[ignoreDblClick] = true;
+ setTimeout(() => {
+ delete input[ignoreDblClick];
+ }, 300);
}
return r;