-
Notifications
You must be signed in to change notification settings - Fork 376
Select Vue Nodes After Drag #5863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import { useVueNodeLifecycle } from '@/composables/graph/useVueNodeLifecycle' | |
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' | ||
import { useCanvasInteractions } from '@/renderer/core/canvas/useCanvasInteractions' | ||
import { useNodeZIndex } from '@/renderer/extensions/vueNodes/composables/useNodeZIndex' | ||
import { isLGraphNode } from '@/utils/litegraphUtil' | ||
|
||
function useNodeEventHandlersIndividual() { | ||
const canvasStore = useCanvasStore() | ||
|
@@ -26,11 +27,7 @@ function useNodeEventHandlersIndividual() { | |
* Handle node selection events | ||
* Supports single selection and multi-select with Ctrl/Cmd | ||
*/ | ||
const handleNodeSelect = ( | ||
event: PointerEvent, | ||
nodeData: VueNodeData, | ||
wasDragging: boolean | ||
) => { | ||
const handleNodeSelect = (event: PointerEvent, nodeData: VueNodeData) => { | ||
if (!shouldHandleNodePointerEvents.value) return | ||
|
||
if (!canvasStore.canvas || !nodeManager.value) return | ||
|
@@ -48,12 +45,13 @@ function useNodeEventHandlersIndividual() { | |
canvasStore.canvas.select(node) | ||
} | ||
} else { | ||
// If it wasn't a drag: single-select the node | ||
if (!wasDragging) { | ||
const selectedMultipleNodes = | ||
canvasStore.selectedItems.filter((n) => isLGraphNode(n)).length > 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels a little weird to me. Can we change the selection logic in useNodePointerInteractions instead? I think we'll have to change the interface there anyway since that's where the dragging logic lives. I would expect the selection to be apparent as I click and drag, not after I release the click. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree - I think we should try to match litegraph behavior exactly (unless it's extremely difficult to do). |
||
if (!selectedMultipleNodes) { | ||
// Single-select the node | ||
canvasStore.canvas.deselectAll() | ||
canvasStore.canvas.select(node) | ||
} | ||
// Regular click -> single select | ||
} | ||
|
||
// Bring node to front when clicked (similar to LiteGraph behavior) | ||
|
@@ -122,7 +120,7 @@ function useNodeEventHandlersIndividual() { | |
// TODO: add custom double-click behavior here | ||
// For now, ensure node is selected | ||
if (!node.selected) { | ||
handleNodeSelect(event, nodeData, false) | ||
handleNodeSelect(event, nodeData) | ||
} | ||
} | ||
|
||
|
@@ -143,7 +141,7 @@ function useNodeEventHandlersIndividual() { | |
|
||
// Select the node if not already selected | ||
if (!node.selected) { | ||
handleNodeSelect(event, nodeData, false) | ||
handleNodeSelect(event, nodeData) | ||
} | ||
|
||
// Let LiteGraph handle the context menu | ||
|
@@ -170,7 +168,7 @@ function useNodeEventHandlersIndividual() { | |
metaKey: event.metaKey, | ||
bubbles: true | ||
}) | ||
handleNodeSelect(syntheticEvent, nodeData, false) | ||
handleNodeSelect(syntheticEvent, nodeData) | ||
} | ||
|
||
// Set drag data for potential drop operations | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can optimize this by just doing a normal
for
loop and returning early if we hit 2, then move it to existing utils file or into the module scope.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long term if we're doing this in multiple places, it might be a candidate for a computed value in the store. Something like
canvasStore.selectedNodesCount
? (Depending on how expensive the filtering ends up being)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last time I checked, canvas.selectedItems is not reactive