( file: DiffFile, highlighted: HighlightedDiffCode | null, theme: AppTheme, )
| 896 | |
| 897 | /** Expand Pierre metadata into the flat stack-view row stream consumed by the renderer. */ |
| 898 | export function buildStackRows( |
| 899 | file: DiffFile, |
| 900 | highlighted: HighlightedDiffCode | null, |
| 901 | theme: AppTheme, |
| 902 | ): DiffRow[] { |
| 903 | const rows: DiffRow[] = []; |
| 904 | const deletionLines = highlighted?.deletionLines ?? []; |
| 905 | const additionLines = highlighted?.additionLines ?? []; |
| 906 | |
| 907 | for (const [hunkIndex, hunk] of file.metadata.hunks.entries()) { |
| 908 | if (hunk.collapsedBefore > 0) { |
| 909 | rows.push({ |
| 910 | type: "collapsed", |
| 911 | key: `${file.id}:stack:collapsed:${hunkIndex}`, |
| 912 | fileId: file.id, |
| 913 | hunkIndex, |
| 914 | text: collapsedRowText(hunk.collapsedBefore), |
| 915 | position: "before", |
| 916 | ...leadingCollapsedRanges(hunk), |
| 917 | }); |
| 918 | } |
| 919 | |
| 920 | rows.push({ |
| 921 | type: "hunk-header", |
| 922 | key: `${file.id}:stack:header:${hunkIndex}`, |
| 923 | fileId: file.id, |
| 924 | hunkIndex, |
| 925 | text: formatHunkHeader(hunk), |
| 926 | }); |
| 927 | |
| 928 | let deletionLineIndex = hunk.deletionLineIndex; |
| 929 | let additionLineIndex = hunk.additionLineIndex; |
| 930 | let deletionLineNumber = hunk.deletionStart; |
| 931 | let additionLineNumber = hunk.additionStart; |
| 932 | |
| 933 | for (const content of hunk.hunkContent) { |
| 934 | if (content.type === "context") { |
| 935 | for (let offset = 0; offset < content.lines; offset += 1) { |
| 936 | rows.push({ |
| 937 | type: "stack-line", |
| 938 | key: `${file.id}:stack:${hunkIndex}:context:${deletionLineIndex + offset}:${additionLineIndex + offset}`, |
| 939 | fileId: file.id, |
| 940 | hunkIndex, |
| 941 | cell: makeStackCell( |
| 942 | "context", |
| 943 | deletionLineNumber + offset, |
| 944 | additionLineNumber + offset, |
| 945 | file.metadata.additionLines[additionLineIndex + offset], |
| 946 | additionLines[additionLineIndex + offset], |
| 947 | theme, |
| 948 | ), |
| 949 | }); |
| 950 | } |
| 951 | |
| 952 | deletionLineIndex += content.lines; |
| 953 | additionLineIndex += content.lines; |
| 954 | deletionLineNumber += content.lines; |
| 955 | additionLineNumber += content.lines; |
no test coverage detected