(
context: Context,
hunkParts: HunkPart[],
lineChanges: (Change[] | null)[]
)
| 101 | * --cc or --combined options, which are defaults for merge commits. |
| 102 | */ |
| 103 | export async function* iterFormatCombinedDiffHunkUnified( |
| 104 | context: Context, |
| 105 | hunkParts: HunkPart[], |
| 106 | lineChanges: (Change[] | null)[] |
| 107 | ): AsyncIterable<FormattedString> { |
| 108 | const lineWidth = context.SCREEN_WIDTH; |
| 109 | |
| 110 | // The final hunk part shows the current state of the file, so we just |
| 111 | // display that with additions and deletions highlighted. |
| 112 | const { fileName, lines, startLineNo } = hunkParts[hunkParts.length - 1]; |
| 113 | let lineNo = startLineNo; |
| 114 | let numDeletes = 0; |
| 115 | |
| 116 | for (let i = 0; i < lines.length; i++) { |
| 117 | const line = lines[i]; |
| 118 | const prefix = line?.slice(0, 1) ?? null; |
| 119 | if (prefix == '-') { |
| 120 | numDeletes++; |
| 121 | } else { |
| 122 | lineNo -= numDeletes; |
| 123 | numDeletes = 0; |
| 124 | } |
| 125 | yield* formatAndFitHunkLine( |
| 126 | context, |
| 127 | lineWidth, |
| 128 | fileName, |
| 129 | lineNo, |
| 130 | line, |
| 131 | lineChanges[i] |
| 132 | ); |
| 133 | lineNo++; |
| 134 | } |
| 135 | } |
no test coverage detected