Skip to content

Commit 2b57291

Browse files
authored
Fix context menu creating nodes in wrong position (#5595)
* Fix context menu creating nodes in wrong position When nodes are created from the context menu, they previously had there position set immediately after the node itself was created. Under some circumstances, this new position would be overwritten by the layout store. This is solved by setting the position before node initialization. * nit: Move size fix to named variable Also remove ternary. The elements are always numberic, so checking if a number is truthy before multiplying by 0 is a little silly. * nit: Further variable extraction
1 parent 62897c6 commit 2b57291

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/lib/litegraph/src/LGraphCanvas.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6314,7 +6314,14 @@ export class LGraphCanvas
63146314
}
63156315

63166316
// that.graph.beforeChange();
6317-
const newNode = LiteGraph.createNode(nodeNewType)
6317+
const xSizeFix = opts.posSizeFix[0] * LiteGraph.NODE_WIDTH
6318+
const ySizeFix = opts.posSizeFix[1] * LiteGraph.NODE_SLOT_HEIGHT
6319+
const nodeX = opts.position[0] + opts.posAdd[0] + xSizeFix
6320+
const nodeY = opts.position[1] + opts.posAdd[1] + ySizeFix
6321+
const pos = [nodeX, nodeY]
6322+
const newNode = LiteGraph.createNode(nodeNewType, nodeNewOpts.title, {
6323+
pos
6324+
})
63186325
if (newNode) {
63196326
// if is object pass options
63206327
if (nodeNewOpts) {
@@ -6341,9 +6348,6 @@ export class LGraphCanvas
63416348
)
63426349
}
63436350
}
6344-
if (nodeNewOpts.title) {
6345-
newNode.title = nodeNewOpts.title
6346-
}
63476351
if (nodeNewOpts.json) {
63486352
newNode.configure(nodeNewOpts.json)
63496353
}
@@ -6353,14 +6357,6 @@ export class LGraphCanvas
63536357
if (!this.graph) throw new NullGraphError()
63546358

63556359
this.graph.add(newNode)
6356-
newNode.pos = [
6357-
opts.position[0] +
6358-
opts.posAdd[0] +
6359-
(opts.posSizeFix[0] ? opts.posSizeFix[0] * newNode.size[0] : 0),
6360-
opts.position[1] +
6361-
opts.posAdd[1] +
6362-
(opts.posSizeFix[1] ? opts.posSizeFix[1] * newNode.size[1] : 0)
6363-
]
63646360

63656361
// Interim API - allow the link connection to be canceled.
63666362
// TODO: https://github.com/Comfy-Org/litegraph.js/issues/946

0 commit comments

Comments
 (0)