The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { ThreadFindStart } from "./threadFind"; |
| 2 | import { collectThreadFindRanges } from "./threadFindHighlights"; |
| 3 | |
| 4 | export function readThreadFindPosition( |
| 5 | container: HTMLElement, |
| 6 | query: string, |
| 7 | resolveEntry: (rowId: string) => string | undefined, |
| 8 | contentInsetEndAdjustment: number, |
| 9 | ): ThreadFindStart | undefined { |
| 10 | const viewport = container.getBoundingClientRect(); |
| 11 | for (const row of container.querySelectorAll<HTMLElement>("[data-timeline-row-id]")) { |
| 12 | const rect = row.getBoundingClientRect(); |
| 13 | if (rect.bottom <= viewport.top || rect.top >= viewport.bottom - contentInsetEndAdjustment) |
| 14 | continue; |
| 15 | const rowId = row.dataset.timelineRowId; |
| 16 | const entryId = rowId ? resolveEntry(rowId) : undefined; |
| 17 | if (!entryId) continue; |
| 18 | const matches = collectThreadFindRanges(row, query); |
| 19 | const next = matches.find((match) => match.range.getBoundingClientRect().bottom > viewport.top); |
| 20 | return { entryId, occurrence: next?.occurrence ?? matches.length }; |
| 21 | } |
| 22 | return undefined; |
| 23 | } |