Skip to content

Commit 69d58f4

Browse files
committed
Changes for subgraph
#28 (comment)
1 parent 0a2b66b commit 69d58f4

File tree

3 files changed

+46
-31
lines changed

3 files changed

+46
-31
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ python -m http.server
2828

2929
## Changelog
3030

31+
2025-08-29 v1.0.21: Changes to get subgraphs working.
3132
2025-08-26 v1.0.20: Disable quick-connections in subgraphs, not working.
3233
2025-08-23 v1.0.19: Possible crashes in subgraph node fix. https://github.com/niknah/quick-connections/issues/25
3334
2025-07-15 v1.0.17: Draw connections in subgraph mode. https://github.com/niknah/quick-connections/issues/24

js/QuickConnection.js

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ export class QuickConnection {
7878
console.error('no canvas', this.canvas); // eslint-disable-line no-console
7979
} else {
8080
this.canvas.canvas.addEventListener('litegraph:canvas', (e) => {
81-
if (this.canvas?.subgraph) {
82-
return;
83-
}
84-
8581
const { detail } = e;
8682
if (!this.release_link_on_empty_shows_menu
8783
&& detail && detail.subType === 'empty-release'
@@ -97,7 +93,7 @@ export class QuickConnection {
9793
try {
9894
this.onDrawOverlay(ctx);
9995
} catch (e) {
100-
console.error('onDrawOverlayCrash', ctx); // eslint-disable-line no-console
96+
console.error('onDrawOverlayCrash', e, ctx); // eslint-disable-line no-console
10197
}
10298
});
10399
}
@@ -115,6 +111,7 @@ export class QuickConnection {
115111
slot: connectingLink.slot,
116112
input: connectingLink.input,
117113
output: connectingLink.output,
114+
pos: connectingLink.pos,
118115
};
119116
}
120117
} else if (this.canvas.connecting_node) {
@@ -139,17 +136,35 @@ export class QuickConnection {
139136

140137
if (this.insideConnection && connectionInfo) {
141138
if (connectionInfo.input) {
142-
this.insideConnection.node.connect(
143-
this.insideConnection.connection_slot_index,
144-
connectionInfo.node,
145-
connectionInfo.slot,
146-
);
139+
if (connectionInfo.node.connect) {
140+
this.insideConnection.node.connect(
141+
this.insideConnection.connection_slot_index,
142+
connectionInfo.node,
143+
connectionInfo.slot,
144+
);
145+
} else {
146+
// subgraph
147+
connectionInfo.input.connect(
148+
this.insideConnection.node.outputs[this.insideConnection.connection_slot_index],
149+
this.insideConnection.node,
150+
);
151+
}
147152
} else {
148-
connectionInfo.node.connect(
149-
connectionInfo.slot,
150-
this.insideConnection.node,
151-
this.insideConnection.connection_slot_index,
152-
);
153+
// output
154+
// eslint-disable-next-line no-lonely-if
155+
if (connectionInfo.node.connect) {
156+
connectionInfo.node.connect(
157+
connectionInfo.slot,
158+
this.insideConnection.node,
159+
this.insideConnection.connection_slot_index,
160+
);
161+
} else {
162+
// subgraph
163+
connectionInfo.output.connect(
164+
this.insideConnection.node.inputs[this.insideConnection.connection_slot_index],
165+
this.insideConnection.node,
166+
);
167+
}
153168
}
154169
return true;
155170
}
@@ -190,7 +205,7 @@ export class QuickConnection {
190205
}
191206
};
192207

193-
const nodes = this.graph._nodes;
208+
const nodes = this.canvas.subgraph?._nodes || this.graph._nodes;
194209
for (let i = 0; i < nodes.length; ++i) {
195210
const node = nodes[i];
196211
if (node.inputs && findInput) {
@@ -224,9 +239,6 @@ export class QuickConnection {
224239
console.error('no canvas or mouse yet', this.canvas); // eslint-disable-line no-console
225240
return;
226241
}
227-
if (this.canvas.subgraph) {
228-
return;
229-
}
230242

231243
this.insideConnection = null;
232244

@@ -240,19 +252,20 @@ export class QuickConnection {
240252
return;
241253
}
242254

243-
ctx.save();
244-
this.canvas.ds.toCanvasContext(ctx);
245-
246255
// const slotPos = new Float32Array(2);
247256

248257
const isInput = input ? true : false;
249258
const connecting = isInput ? input : output;
250259
const connectionSlot = slot;
251260

252-
const pos = isInput ?
253-
node.getInputPos(connectionSlot)
254-
: node.getOutputPos(connectionSlot);
255-
261+
let pos;
262+
if (!node.getOutputPos || !node.getInputPos) {
263+
pos = connectionInfo.pos;
264+
} else {
265+
pos = isInput ?
266+
node.getInputPos(connectionSlot)
267+
: node.getOutputPos(connectionSlot);
268+
}
256269
if (!this.acceptingNodes) {
257270
this.acceptingNodes = this.findAcceptingNodes(
258271
connecting,
@@ -269,10 +282,8 @@ export class QuickConnection {
269282

270283
const buttonShift = [
271284
isInput ? -32 : +32,
272-
// force for now so the dots don't move around when the tooltip pops up.
273-
// No need to avoid tool tip if we're using the input,
274-
// tool tip is visible to the right of dot
275-
isInput ? 0 : LiteGraph.NODE_SLOT_HEIGHT,
285+
// 2025-08-29: tooltip seems to be far away now, don't change position
286+
0,
276287
/*
277288
(true || this.acceptingNodes.length === 1 || hasNodeTooltip)
278289
? 0
@@ -313,6 +324,9 @@ export class QuickConnection {
313324
let boxRect = null;
314325
const textsToDraw = [];
315326

327+
ctx.save();
328+
this.canvas.ds.toCanvasContext(ctx);
329+
316330
// const oldFillStyle = ctx.fillStyle;
317331
if (isInsideClosePosition) {
318332
const oldFont = ctx.font;

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "quick-connections"
33
description = "Quick connections, Circuit board connections"
4-
version = "1.0.20"
4+
version = "1.0.21"
55
license = {text = "MIT License"}
66

77
[project.urls]

0 commit comments

Comments
 (0)