mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-04-20 03:13:30 +00:00
Prevent exactly overlapping nodes
Throttle double click
This commit is contained in:
parent
1fa9ccaa16
commit
d6830b958c
@ -139,17 +139,41 @@ app.registerExtension({
|
|||||||
return r;
|
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
|
// Double click a widget input to automatically attach a primitive
|
||||||
const origOnInputDblClick = nodeType.prototype.onInputDblClick;
|
const origOnInputDblClick = nodeType.prototype.onInputDblClick;
|
||||||
|
const ignoreDblClick = Symbol();
|
||||||
nodeType.prototype.onInputDblClick = function (slot) {
|
nodeType.prototype.onInputDblClick = function (slot) {
|
||||||
const r = origOnInputDblClick ? origOnInputDblClick.apply(this, arguments) : undefined;
|
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");
|
const node = LiteGraph.createNode("PrimitiveNode");
|
||||||
app.graph.add(node);
|
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.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;
|
return r;
|
||||||
|
Loading…
Reference in New Issue
Block a user