Fix reroute snap alignment

This commit is contained in:
Austin Mroz
2026-03-17 17:44:06 -07:00
parent aa407e7cd4
commit 6dd413566f
2 changed files with 12 additions and 4 deletions

View File

@@ -5882,7 +5882,8 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
drawSnapGuide(
ctx: CanvasRenderingContext2D,
item: Positionable,
shape = RenderShape.ROUND
shape = RenderShape.ROUND,
{ offsetToSlot }: { offsetToSlot?: boolean } = {}
) {
const snapGuide = temp
snapGuide.set(item.boundingRect)
@@ -5890,7 +5891,10 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
// Not all items have pos equal to top-left of bounds
const { pos } = item
const offsetX = pos[0] - snapGuide[0]
const offsetY = pos[1] - snapGuide[1]
const offsetY =
pos[1] -
snapGuide[1] -
(offsetToSlot ? LiteGraph.NODE_SLOT_HEIGHT * 0.7 : 0)
// Normalise boundingRect to pos to snap
snapGuide[0] += offsetX
@@ -6067,7 +6071,9 @@ export class LGraphCanvas implements CustomEventDispatcher<LGraphCanvasEventMap>
this.isDragging &&
this.selectedItems.has(reroute)
) {
this.drawSnapGuide(ctx, reroute, RenderShape.CIRCLE)
this.drawSnapGuide(ctx, reroute, RenderShape.CIRCLE, {
offsetToSlot: true
})
}
reroute.draw(ctx, this._pattern)

View File

@@ -16,6 +16,7 @@ import type {
ReadOnlyRect,
ReadonlyLinkNetwork
} from './interfaces'
import { LiteGraph } from './litegraph'
import { distance, isPointInRect } from './measure'
import type { Serialisable, SerialisableReroute } from './types/serialisation'
@@ -428,9 +429,10 @@ export class Reroute
snapToGrid(snapTo: number): boolean {
if (!snapTo) return false
const offsetY = LiteGraph.NODE_SLOT_HEIGHT * 0.7
const { pos } = this
pos[0] = snapTo * Math.round(pos[0] / snapTo)
pos[1] = snapTo * Math.round(pos[1] / snapTo)
pos[1] = snapTo * Math.round((pos[1] - offsetY) / snapTo) + offsetY
return true
}