The best way to control Claude Code, Codex and more from any computer or phone

main
ts 27 lines 1.03 KB
Raw
1 import type { FileDiffMetadata } from "@pierre/diffs";
2 import type { PullRequestDiffSide } from "@t3tools/contracts";
3
4 /** Only rendered hunks can anchor comments; list others off-diff. */
5 export function isLineInFileDiff(
6 file: FileDiffMetadata,
7 side: PullRequestDiffSide,
8 line: number,
9 ): boolean {
10 return file.hunks.some((hunk) =>
11 side === "left"
12 ? line >= hunk.deletionStart && line < hunk.deletionStart + hunk.deletionCount
13 : line >= hunk.additionStart && line < hunk.additionStart + hunk.additionCount,
14 );
15 }
16
17 export function getFileViewedRange<T extends { readonly fileKey: string }>(
18 files: ReadonlyArray<T>,
19 fileKey: string,
20 anchorFileKey: string | null,
21 ): ReadonlyArray<T> {
22 const index = files.findIndex((file) => file.fileKey === fileKey);
23 if (index === -1) return [];
24 const anchorIndex = files.findIndex((file) => file.fileKey === anchorFileKey);
25 if (anchorIndex === -1) return files.slice(index, index + 1);
26 return files.slice(Math.min(index, anchorIndex), Math.max(index, anchorIndex) + 1);
27 }