| 86 | let trailingContext = 0 |
| 87 | |
| 88 | const flush = () => { |
| 89 | if (hunk.length === 0) return |
| 90 | // Drop context beyond the hunk's trailing window. |
| 91 | const extra = Math.max(0, trailingContext - contextLines) |
| 92 | if (extra > 0) { |
| 93 | hunk = hunk.slice(0, hunk.length - extra) |
| 94 | hunkOldCount -= extra |
| 95 | hunkNewCount -= extra |
| 96 | } |
| 97 | out.push(`@@ -${hunkOldStart},${hunkOldCount} +${hunkNewStart},${hunkNewCount} @@`) |
| 98 | out.push(...hunk) |
| 99 | hunk = [] |
| 100 | hunkOldCount = 0 |
| 101 | hunkNewCount = 0 |
| 102 | trailingContext = 0 |
| 103 | } |
| 104 | |
| 105 | let pendingContext: string[] = [] |
| 106 | for (const op of ops) { |