@@ -234,6 +234,7 @@ const WorkflowContent = React.memo(() => {
234234 const [ potentialParentId , setPotentialParentId ] = useState < string | null > ( null )
235235 const [ selectedEdges , setSelectedEdges ] = useState < SelectedEdgesMap > ( new Map ( ) )
236236 const [ isErrorConnectionDrag , setIsErrorConnectionDrag ] = useState ( false )
237+ const selectedIdsRef = useRef < string [ ] | null > ( null )
237238 const canvasMode = useCanvasModeStore ( ( state ) => state . mode )
238239 const isHandMode = canvasMode === 'hand'
239240 const { handleCanvasMouseDown, selectionProps } = useShiftSelectionLock ( { isHandMode } )
@@ -864,7 +865,7 @@ const WorkflowContent = React.memo(() => {
864865 handlePaneContextMenu,
865866 handleSelectionContextMenu,
866867 closeMenu : closeContextMenu ,
867- } = useCanvasContextMenu ( { blocks, getNodes } )
868+ } = useCanvasContextMenu ( { blocks, getNodes, setNodes } )
868869
869870 const handleContextCopy = useCallback ( ( ) => {
870871 const blockIds = contextMenuBlocks . map ( ( b ) => b . id )
@@ -2153,11 +2154,22 @@ const WorkflowContent = React.memo(() => {
21532154 /** Handles node changes - applies changes and resolves parent-child selection conflicts. */
21542155 const onNodesChange = useCallback (
21552156 ( changes : NodeChange [ ] ) => {
2157+ selectedIdsRef . current = null
21562158 setDisplayNodes ( ( nds ) => {
21572159 const updated = applyNodeChanges ( changes , nds )
21582160 const hasSelectionChange = changes . some ( ( c ) => c . type === 'select' )
2159- return hasSelectionChange ? resolveParentChildSelectionConflicts ( updated , blocks ) : updated
2161+ if ( ! hasSelectionChange ) return updated
2162+ const resolved = resolveParentChildSelectionConflicts ( updated , blocks )
2163+ selectedIdsRef . current = resolved . filter ( ( node ) => node . selected ) . map ( ( node ) => node . id )
2164+ return resolved
21602165 } )
2166+ const selectedIds = selectedIdsRef . current as string [ ] | null
2167+ if ( selectedIds !== null ) {
2168+ const { currentBlockId, clearCurrentBlock } = usePanelEditorStore . getState ( )
2169+ if ( currentBlockId && selectedIds . indexOf ( currentBlockId ) === - 1 ) {
2170+ clearCurrentBlock ( )
2171+ }
2172+ }
21612173 } ,
21622174 [ blocks ]
21632175 )
0 commit comments