Repository navigation
Description
Summary
src/diagram/Editor.tsx has a single canonical selection-change handler, handleSelection(selection: ReadonlySet<UID>) (around line 699), which does three things:
setState({ selection, flowStillBeingCreated: false, variableDetailsActiveTab: 0 })- When the new selection is empty, also
setState({ showDetails: undefined })-- resets the variable-details panel state. - Notifies the optional
onSelectionChanged?: (idents: string[]) => voidprop via a deferredsetTimeout(..., 0)that readsgetSelectionIdents()after React commits the new selection.
Several other handlers mutate state.selection directly via setState/setStateForView instead of routing through handleSelection, so they skip steps 2 and/or 3:
handleSelectionDelete(around line 747, clears at ~line 816-818):this.setState({ selection: new Set<number>() }). LeavesshowDetailsat whatever it was (e.g.'variable') even though there is no selection, and does not notifyonSelectionChangedthat the selection was cleared by the delete.handleFlowAttach(around line 835, clears at ~line 1369): setsselection: new Set<number>()-- noshowDetailsreset, noonSelectionChanged.handleSelectionMove(around line 1373) and the undo/redo path (around line 1814) -- setshowDetails: undefinedbut do not notifyonSelectionChanged.handleNavigateBack/handleNavigateToLevel(around lines 1823 / 1848) -- restore the parent's selection and do setshowDetails: undefined, but do not notifyonSelectionChanged.
Why it matters
- Stale UI state: After
handleSelectionDelete,state.showDetailscan remain'variable'with an empty selection -- an inconsistent state. Currently masked becausegetVariableDetails()also checksgetNamedSelectedElement()(returns undefined for an empty selection), so the panel doesn't render -- but the state is wrong and a future change to that render guard would surface it. - Broken host contract:
onSelectionChangedis documented (seesrc/diagram/CLAUDE.md) as firing "after each selection change" and is consumed bysimlin-serve'sEditorHostto forward selection state to backend listeners. Hosts that subscribe are not told the selection was cleared when the user deletes the selected element(s), or when navigating in/out of modules.src/app'sHostedWebEditordoes not subscribe, so the web app is unaffected, but the contract is violated for serve and any other subscriber.
Component(s) affected
src/diagram--Editor.tsx(handleSelection,handleSelectionDelete,handleFlowAttach,handleSelectionMove,handleNavigateBack,handleNavigateToLevel, undo/redo handler)- Downstream:
src/simlin-serveEditorHost(subscriber toonSelectionChanged)
Possible approach
Route all state.selection mutations through a single helper (or through handleSelection itself) so the showDetails-reset-on-empty and the deferred onSelectionChanged notification happen consistently. Handlers that also need to set view state can compose the selection helper with their own setState. At minimum, handleSelectionDelete should clear showDetails and notify onSelectionChanged when it empties the selection.
Care needed around the existing selectionDeferralTimer bookkeeping (instance field cancelled in componentWillUnmount, superseded by newer selections) so consolidation doesn't introduce duplicate or lost notifications.
How discovered
Noticed while fixing an unrelated bug in src/diagram/Editor.tsx -- pre-existing inconsistency between handleSelectionDelete and handleSelection.
Activity