Skip to content

Commit 424bd21

Browse files
authored
fix: move selected groups when dragging nodes in vueNodes mode (#7306)
## Summary Captures selected groups at drag start and moves them using frame delta to match LiteGraph's behavior. Litegraph doesn't have this issue. ## Screenshots (if applicable) ### Before https://github.com/user-attachments/assets/0e4ff907-376e-438b-aa89-106c146a8ac1 ### After https://github.com/user-attachments/assets/d954da99-3468-4bd8-9e1a-835e1a90a3bd ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7306-fix-move-selected-groups-when-dragging-nodes-in-vueNodes-mode-2c56d73d3650816a83efd11bbc36262e) by [Unito](https://www.unito.io)
1 parent 04286c0 commit 424bd21

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/renderer/extensions/vueNodes/layout/useNodeDrag.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { storeToRefs } from 'pinia'
22
import { toValue } from 'vue'
33

4+
import type { LGraphGroup } from '@/lib/litegraph/src/LGraphGroup'
45
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
56
import { useLayoutMutations } from '@/renderer/core/layout/operations/layoutMutations'
67
import { layoutStore } from '@/renderer/core/layout/store/layoutStore'
@@ -13,13 +14,14 @@ import type {
1314
import { useNodeSnap } from '@/renderer/extensions/vueNodes/composables/useNodeSnap'
1415
import { useShiftKeySync } from '@/renderer/extensions/vueNodes/composables/useShiftKeySync'
1516
import { useTransformState } from '@/renderer/core/layout/transform/useTransformState'
17+
import { isLGraphGroup } from '@/utils/litegraphUtil'
1618
import { createSharedComposable } from '@vueuse/core'
1719

1820
export const useNodeDrag = createSharedComposable(useNodeDragIndividual)
1921

2022
function useNodeDragIndividual() {
2123
const mutations = useLayoutMutations()
22-
const { selectedNodeIds } = storeToRefs(useCanvasStore())
24+
const { selectedNodeIds, selectedItems } = storeToRefs(useCanvasStore())
2325

2426
// Get transform utilities from TransformPane if available
2527
const transformState = useTransformState()
@@ -37,6 +39,10 @@ function useNodeDragIndividual() {
3739
let rafId: number | null = null
3840
let stopShiftSync: (() => void) | null = null
3941

42+
// For groups: track the last applied canvas delta to compute frame delta
43+
let lastCanvasDelta: Point | null = null
44+
let selectedGroups: LGraphGroup[] | null = null
45+
4046
function startDrag(event: PointerEvent, nodeId: NodeId) {
4147
const layout = toValue(layoutStore.getNodeLayoutRef(nodeId))
4248
if (!layout) return
@@ -67,6 +73,10 @@ function useNodeDragIndividual() {
6773
otherSelectedNodesStartPositions = null
6874
}
6975

76+
// Capture selected groups (filter from selectedItems which only contains selected items)
77+
selectedGroups = toValue(selectedItems).filter(isLGraphGroup)
78+
lastCanvasDelta = { x: 0, y: 0 }
79+
7080
mutations.setSource(LayoutSource.Vue)
7181
}
7282

@@ -127,6 +137,21 @@ function useNodeDragIndividual() {
127137
mutations.moveNode(otherNodeId, newOtherPosition)
128138
}
129139
}
140+
141+
// Move selected groups using frame delta (difference from last frame)
142+
// This matches LiteGraph's behavior which uses delta-based movement
143+
if (selectedGroups && selectedGroups.length > 0 && lastCanvasDelta) {
144+
const frameDelta = {
145+
x: canvasDelta.x - lastCanvasDelta.x,
146+
y: canvasDelta.y - lastCanvasDelta.y
147+
}
148+
149+
for (const group of selectedGroups) {
150+
group.move(frameDelta.x, frameDelta.y, true)
151+
}
152+
}
153+
154+
lastCanvasDelta = canvasDelta
130155
})
131156
}
132157

@@ -195,6 +220,8 @@ function useNodeDragIndividual() {
195220
dragStartPos = null
196221
dragStartMouse = null
197222
otherSelectedNodesStartPositions = null
223+
selectedGroups = null
224+
lastCanvasDelta = null
198225

199226
// Stop tracking shift key state
200227
stopShiftSync?.()

0 commit comments

Comments
 (0)