Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
25 lines
1.1 KiB
TypeScript
25 lines
1.1 KiB
TypeScript
import type { ThreadFindStart } from "./threadFind";
|
|
import { collectThreadFindRanges } from "./threadFindHighlights";
|
|
|
|
/** Anchor to the first row being read, skipping occurrences above its viewport. */
|
|
export function readThreadFindPosition(
|
|
container: HTMLElement,
|
|
query: string,
|
|
resolveEntry: (rowId: string) => string | undefined,
|
|
contentInsetEndAdjustment: number,
|
|
): ThreadFindStart | undefined {
|
|
const viewport = container.getBoundingClientRect();
|
|
for (const row of container.querySelectorAll<HTMLElement>("[data-timeline-row-id]")) {
|
|
const rect = row.getBoundingClientRect();
|
|
if (rect.bottom <= viewport.top || rect.top >= viewport.bottom - contentInsetEndAdjustment)
|
|
continue;
|
|
const rowId = row.dataset.timelineRowId;
|
|
const entryId = rowId ? resolveEntry(rowId) : undefined;
|
|
if (!entryId) continue;
|
|
const matches = collectThreadFindRanges(row, query);
|
|
const next = matches.find((match) => match.range.getBoundingClientRect().bottom > viewport.top);
|
|
return { entryId, occurrence: next?.occurrence ?? matches.length };
|
|
}
|
|
return undefined;
|
|
}
|