Skip to content

Commit

Permalink
fix: widget persistence (#535)
Browse files Browse the repository at this point in the history
Ensure that that user widgets are not remounted when the cursor moves, so that their component state persists.
  • Loading branch information
Vtec234 authored Oct 17, 2024
1 parent 32036f9 commit 4ffed87
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lean4-infoview/src/infoview/info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ function GoalInfoDisplay(props: GoalInfoDisplayProps) {

const [selectedLocs, setSelectedLocs] = React.useState<GoalsLocation[]>([])

// https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
const [prevPos, setPrevPos] = React.useState<DocumentPosition>(pos)
if (!DocumentPosition.isEqual(pos, prevPos)) {
setPrevPos(pos)
setSelectedLocs([])
}

const locs: Locations = React.useMemo(
() => ({
isSelected: (l: GoalsLocation) => selectedLocs.some(v => GoalsLocation.isEqual(v, l)),
Expand Down Expand Up @@ -218,13 +225,7 @@ const InfoDisplayContent = React.memo((props: InfoDisplayContentProps) => {
</a>
</div>
)}
<GoalInfoDisplay
key={DocumentPosition.toString(pos)}
pos={pos}
goals={goals}
termGoal={termGoal}
userWidgets={userWidgets}
/>
<GoalInfoDisplay pos={pos} goals={goals} termGoal={termGoal} userWidgets={userWidgets} />
<div style={{ display: hasMessages ? 'block' : 'none' }} key="messages">
<Details initiallyOpen key="messages">
<>Messages ({messages.length})</>
Expand Down

0 comments on commit 4ffed87

Please sign in to comment.