Skip to content

Commit 0153cd4

Browse files
committed
fix(tables): strand an in-flight match jump when the search term changes
1 parent a4a71ac commit 0153cd4

1 file changed

Lines changed: 16 additions & 7 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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,21 @@ export function TableGrid({
12411241
setSelectionAnchor({ rowIndex, colIndex })
12421242
}, [rows, displayColumns, pendingMatchTick])
12431243

1244+
/**
1245+
* Any change of term strands a jump still paging toward the previous term's
1246+
* match. Declared above the auto-reveal so it runs first: without it that
1247+
* jump can finish, pass its own sequence check, and reveal a cell that no
1248+
* longer matches — most visibly when the new term's first hit isn't loaded,
1249+
* so nothing else moves the selection afterwards. Clearing and closing land
1250+
* here too, since both drive `submittedQuery` to `''`.
1251+
*/
1252+
useEffect(() => {
1253+
goToMatchSeqRef.current++
1254+
pendingMatchRef.current = null
1255+
cursorIsOnMatchRef.current = false
1256+
setIsJumping(false)
1257+
}, [submittedQuery])
1258+
12441259
/**
12451260
* A new TERM resets to its first match and reveals it.
12461261
*
@@ -1263,14 +1278,8 @@ export function TableGrid({
12631278
if (submittedQuery.length === 0) {
12641279
// Clearing the box has to un-latch, or retyping the same term — the
12651280
// ordinary "did I typo that?" correction — would match the stale latch
1266-
// and neither reset the cursor nor reveal anything. It also cancels an
1267-
// in-flight jump, exactly as closing does: otherwise a Next still paging
1268-
// when the term is cleared lands on a match whose highlight is gone.
1281+
// and neither reset the cursor nor reveal anything.
12691282
autoRevealedTermRef.current = ''
1270-
goToMatchSeqRef.current++
1271-
pendingMatchRef.current = null
1272-
cursorIsOnMatchRef.current = false
1273-
setIsJumping(false)
12741283
return
12751284
}
12761285
// Wait for THIS term's own result set. `keepPreviousData` leaves

0 commit comments

Comments
 (0)