mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-03 04:00:31 +00:00
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
This commit is contained in:
@@ -6314,7 +6314,14 @@ export class LGraphCanvas
|
||||
}
|
||||
|
||||
// that.graph.beforeChange();
|
||||
const newNode = LiteGraph.createNode(nodeNewType)
|
||||
const xSizeFix = opts.posSizeFix[0] * LiteGraph.NODE_WIDTH
|
||||
const ySizeFix = opts.posSizeFix[1] * LiteGraph.NODE_SLOT_HEIGHT
|
||||
const nodeX = opts.position[0] + opts.posAdd[0] + xSizeFix
|
||||
const nodeY = opts.position[1] + opts.posAdd[1] + ySizeFix
|
||||
const pos = [nodeX, nodeY]
|
||||
const newNode = LiteGraph.createNode(nodeNewType, nodeNewOpts.title, {
|
||||
pos
|
||||
})
|
||||
if (newNode) {
|
||||
// if is object pass options
|
||||
if (nodeNewOpts) {
|
||||
@@ -6341,9 +6348,6 @@ export class LGraphCanvas
|
||||
)
|
||||
}
|
||||
}
|
||||
if (nodeNewOpts.title) {
|
||||
newNode.title = nodeNewOpts.title
|
||||
}
|
||||
if (nodeNewOpts.json) {
|
||||
newNode.configure(nodeNewOpts.json)
|
||||
}
|
||||
@@ -6353,14 +6357,6 @@ export class LGraphCanvas
|
||||
if (!this.graph) throw new NullGraphError()
|
||||
|
||||
this.graph.add(newNode)
|
||||
newNode.pos = [
|
||||
opts.position[0] +
|
||||
opts.posAdd[0] +
|
||||
(opts.posSizeFix[0] ? opts.posSizeFix[0] * newNode.size[0] : 0),
|
||||
opts.position[1] +
|
||||
opts.posAdd[1] +
|
||||
(opts.posSizeFix[1] ? opts.posSizeFix[1] * newNode.size[1] : 0)
|
||||
]
|
||||
|
||||
// Interim API - allow the link connection to be canceled.
|
||||
// TODO: https://github.com/Comfy-Org/litegraph.js/issues/946
|
||||
|
||||
Reference in New Issue
Block a user