@@ -2302,41 +2302,20 @@ const WorkflowContent = React.memo(() => {
23022302 window . removeEventListener ( 'remove-from-subflow' , handleRemoveFromSubflow as EventListener )
23032303 } , [ blocks , edgesForDisplay , getNodeAbsolutePosition , collaborativeBatchUpdateParent ] )
23042304
2305- /** Handles node changes - applies changes and resolves parent-child selection conflicts. */
2306- const onNodesChange = useCallback (
2307- ( changes : NodeChange [ ] ) => {
2308- selectedIdsRef . current = null
2309- setDisplayNodes ( ( nds ) => {
2310- const updated = applyNodeChanges ( changes , nds )
2311- const hasSelectionChange = changes . some ( ( c ) => c . type === 'select' )
2312- if ( ! hasSelectionChange ) return updated
2313- const resolved = resolveParentChildSelectionConflicts ( updated , blocks )
2314- selectedIdsRef . current = resolved . filter ( ( node ) => node . selected ) . map ( ( node ) => node . id )
2315- return resolved
2316- } )
2317- const selectedIds = selectedIdsRef . current as string [ ] | null
2318- if ( selectedIds !== null ) {
2319- syncPanelWithSelection ( selectedIds )
2320- }
2321- } ,
2322- [ blocks ]
2323- )
2324-
23252305 /**
2326- * Updates container dimensions in displayNodes during drag.
2327- * This allows live resizing of containers as their children are dragged.
2306+ * Updates container dimensions in displayNodes during drag or keyboard movement.
23282307 */
2329- const updateContainerDimensionsDuringDrag = useCallback (
2330- ( draggedNodeId : string , draggedNodePosition : { x : number ; y : number } ) => {
2331- const parentId = blocks [ draggedNodeId ] ?. data ?. parentId
2308+ const updateContainerDimensionsDuringMove = useCallback (
2309+ ( movedNodeId : string , movedNodePosition : { x : number ; y : number } ) => {
2310+ const parentId = blocks [ movedNodeId ] ?. data ?. parentId
23322311 if ( ! parentId ) return
23332312
23342313 setDisplayNodes ( ( currentNodes ) => {
23352314 const childNodes = currentNodes . filter ( ( n ) => n . parentId === parentId )
23362315 if ( childNodes . length === 0 ) return currentNodes
23372316
23382317 const childPositions = childNodes . map ( ( node ) => {
2339- const nodePosition = node . id === draggedNodeId ? draggedNodePosition : node . position
2318+ const nodePosition = node . id === movedNodeId ? movedNodePosition : node . position
23402319 const { width, height } = getBlockDimensions ( node . id )
23412320 return { x : nodePosition . x , y : nodePosition . y , width, height }
23422321 } )
@@ -2367,6 +2346,34 @@ const WorkflowContent = React.memo(() => {
23672346 [ blocks , getBlockDimensions ]
23682347 )
23692348
2349+ /** Handles node changes - applies changes and resolves parent-child selection conflicts. */
2350+ const onNodesChange = useCallback (
2351+ ( changes : NodeChange [ ] ) => {
2352+ selectedIdsRef . current = null
2353+ setDisplayNodes ( ( nds ) => {
2354+ const updated = applyNodeChanges ( changes , nds )
2355+ const hasSelectionChange = changes . some ( ( c ) => c . type === 'select' )
2356+ if ( ! hasSelectionChange ) return updated
2357+ const resolved = resolveParentChildSelectionConflicts ( updated , blocks )
2358+ selectedIdsRef . current = resolved . filter ( ( node ) => node . selected ) . map ( ( node ) => node . id )
2359+ return resolved
2360+ } )
2361+ const selectedIds = selectedIdsRef . current as string [ ] | null
2362+ if ( selectedIds !== null ) {
2363+ syncPanelWithSelection ( selectedIds )
2364+ }
2365+
2366+ // Handle position changes (e.g., from keyboard arrow key movement)
2367+ // Update container dimensions when child nodes are moved
2368+ for ( const change of changes ) {
2369+ if ( change . type === 'position' && 'position' in change && change . position ) {
2370+ updateContainerDimensionsDuringMove ( change . id , change . position )
2371+ }
2372+ }
2373+ } ,
2374+ [ blocks , updateContainerDimensionsDuringMove ]
2375+ )
2376+
23702377 /**
23712378 * Effect to resize loops when nodes change (add/remove/position change).
23722379 * Runs on structural changes only - not during drag (position-only changes).
@@ -2611,7 +2618,7 @@ const WorkflowContent = React.memo(() => {
26112618
26122619 // If the node is inside a container, update container dimensions during drag
26132620 if ( currentParentId ) {
2614- updateContainerDimensionsDuringDrag ( node . id , node . position )
2621+ updateContainerDimensionsDuringMove ( node . id , node . position )
26152622 }
26162623
26172624 // Check if this is a starter block - starter blocks should never be in containers
@@ -2728,7 +2735,7 @@ const WorkflowContent = React.memo(() => {
27282735 blocks ,
27292736 getNodeAbsolutePosition ,
27302737 getNodeDepth ,
2731- updateContainerDimensionsDuringDrag ,
2738+ updateContainerDimensionsDuringMove ,
27322739 highlightContainerNode ,
27332740 ]
27342741 )
0 commit comments