@@ -169,16 +169,17 @@ function mapEdgesByNode(edges: Edge[], nodeIds: Set<string>): Map<string, Edge[]
169169
170170/**
171171 * Syncs the panel editor with the current selection state.
172- * Shows block details when exactly one block is selected, clears otherwise .
172+ * Shows the last selected block in the panel. Clears when nothing is selected.
173173 */
174174function syncPanelWithSelection ( selectedIds : string [ ] ) {
175175 const { currentBlockId, clearCurrentBlock, setCurrentBlockId } = usePanelEditorStore . getState ( )
176- if ( selectedIds . length === 1 && selectedIds [ 0 ] !== currentBlockId ) {
177- setCurrentBlockId ( selectedIds [ 0 ] )
178- } else if ( selectedIds . length === 0 && currentBlockId ) {
179- clearCurrentBlock ( )
180- } else if ( selectedIds . length > 1 && currentBlockId ) {
181- clearCurrentBlock ( )
176+ if ( selectedIds . length === 0 ) {
177+ if ( currentBlockId ) clearCurrentBlock ( )
178+ } else {
179+ const lastSelectedId = selectedIds [ selectedIds . length - 1 ]
180+ if ( lastSelectedId !== currentBlockId ) {
181+ setCurrentBlockId ( lastSelectedId )
182+ }
182183 }
183184}
184185
@@ -2477,10 +2478,15 @@ const WorkflowContent = React.memo(
24772478 // Local state for nodes - allows smooth drag without store updates on every frame
24782479 const [ displayNodes , setDisplayNodes ] = useState < Node [ ] > ( [ ] )
24792480
2481+ const selectedNodeIds = useMemo (
2482+ ( ) => displayNodes . filter ( ( node ) => node . selected ) . map ( ( node ) => node . id ) ,
2483+ [ displayNodes ]
2484+ )
2485+ const selectedNodeIdsKey = selectedNodeIds . join ( ',' )
2486+
24802487 useEffect ( ( ) => {
2481- const selectedIds = displayNodes . filter ( ( node ) => node . selected ) . map ( ( node ) => node . id )
2482- syncPanelWithSelection ( selectedIds )
2483- } , [ displayNodes ] )
2488+ syncPanelWithSelection ( selectedNodeIds )
2489+ } , [ selectedNodeIdsKey ] )
24842490
24852491 useEffect ( ( ) => {
24862492 // Check for pending selection (from paste/duplicate), otherwise preserve existing selection
0 commit comments