Skip to content

Commit fd24b2d

Browse files
committed
fix(tables): release the find cursor when its match leaves the result set
1 parent b197d55 commit fd24b2d

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/table-grid.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,10 @@ export function TableGrid({
12311231
const wrapped = ((index % matches.length) + matches.length) % matches.length
12321232
const match = matches[wrapped]
12331233
setCurrentMatchIndex(wrapped)
1234+
// Claim the target NOW, not when the reveal lands. Paging is awaited below,
1235+
// and a same-term refetch during that window would otherwise re-point the
1236+
// cursor at the cell we are navigating AWAY from.
1237+
activeMatchRef.current = match
12341238
setIsJumping(true)
12351239
// Paging to a distant match can outlast the next keystroke now that the
12361240
// search runs as the user types. Stamp this jump and drop it on return if a
@@ -1292,7 +1296,6 @@ export function TableGrid({
12921296
setRowSelection((prev) => (prev.kind === 'none' ? prev : ROW_SELECTION_NONE))
12931297
setSelectionFocus(null)
12941298
cursorIsOnMatchRef.current = true
1295-
activeMatchRef.current = match
12961299
setSelectionAnchor({ rowIndex, colIndex })
12971300
}, [rows, displayColumns, pendingMatchTick])
12981301

@@ -1306,16 +1309,25 @@ export function TableGrid({
13061309
* on (rowId, column) — the match's identity — keeps the cursor attached to the
13071310
* cell rather than the position.
13081311
*
1309-
* When the active match is gone entirely there is nothing to re-point at;
1310-
* `stepBaseIndex` clamps the now-possibly-out-of-range index instead.
1312+
* When the active match is gone from the set — its row deleted, its cell
1313+
* edited so it no longer matches — the cursor is released instead: it is no
1314+
* longer sitting on a hit, so the next step must LAND on the clamped index
1315+
* rather than move past it. Without that, deleting the match under the cursor
1316+
* makes Next skip the one that took its place.
13111317
*/
13121318
useEffect(() => {
13131319
const active = activeMatchRef.current
13141320
if (!active || findMatches.length === 0) return
13151321
const index = findMatches.findIndex(
13161322
(m) => m.rowId === active.rowId && m.column === active.column
13171323
)
1318-
if (index !== -1 && index !== currentMatchIndexRef.current) setCurrentMatchIndex(index)
1324+
if (index === -1) {
1325+
activeMatchRef.current = null
1326+
cursorIsOnMatchRef.current = false
1327+
setCurrentMatchIndex((i) => Math.min(i, findMatches.length - 1))
1328+
return
1329+
}
1330+
if (index !== currentMatchIndexRef.current) setCurrentMatchIndex(index)
13191331
}, [findMatches])
13201332

13211333
/**

0 commit comments

Comments
 (0)