The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { NativeReviewDiffRow } from "../../diffs/nativeReviewDiffSurface"; |
| 2 | |
| 3 | export type GuideDiffFocus = { |
| 4 | readonly side: "old" | "new"; |
| 5 | readonly endSide?: "old" | "new"; |
| 6 | readonly start: number; |
| 7 | readonly end: number; |
| 8 | }; |
| 9 | |
| 10 | export function guideFocusedRows( |
| 11 | rows: readonly NativeReviewDiffRow[], |
| 12 | fileId: string | undefined, |
| 13 | focus: GuideDiffFocus | undefined, |
| 14 | ) { |
| 15 | if (!fileId || !focus) return []; |
| 16 | if (focus.endSide && focus.endSide !== focus.side) { |
| 17 | const start = rows.findIndex( |
| 18 | (row) => |
| 19 | row.fileId === fileId && |
| 20 | (focus.side === "old" ? row.oldLineNumber : row.newLineNumber) === focus.start, |
| 21 | ); |
| 22 | const end = rows.findIndex( |
| 23 | (row) => |
| 24 | row.fileId === fileId && |
| 25 | (focus.endSide === "old" ? row.oldLineNumber : row.newLineNumber) === focus.end, |
| 26 | ); |
| 27 | return start < 0 || end < 0 |
| 28 | ? [] |
| 29 | : rows |
| 30 | .slice(Math.min(start, end), Math.max(start, end) + 1) |
| 31 | .filter((row) => row.fileId === fileId && row.kind === "line"); |
| 32 | } |
| 33 | return rows.filter((row) => { |
| 34 | const line = focus.side === "old" ? row.oldLineNumber : row.newLineNumber; |
| 35 | return ( |
| 36 | row.fileId === fileId && |
| 37 | row.kind === "line" && |
| 38 | line != null && |
| 39 | line >= focus.start && |
| 40 | line <= focus.end |
| 41 | ); |
| 42 | }); |
| 43 | } |