* Find areas of change in the diff lines.
( diffLines: DiffLine[], )
| 319 | * Find areas of change in the diff lines. |
| 320 | */ |
| 321 | function findChangedAreas( |
| 322 | diffLines: DiffLine[], |
| 323 | ): { start: number; end: number }[] { |
| 324 | const changedAreas: { start: number; end: number }[] = []; |
| 325 | let changedAreaStart = -1; |
| 326 | |
| 327 | for (let i = 0; i < diffLines.length; i++) { |
| 328 | if (diffLines[i].type !== "same" && changedAreaStart === -1) { |
| 329 | changedAreaStart = i; |
| 330 | } else if (diffLines[i].type === "same" && changedAreaStart !== -1) { |
| 331 | // We've found the end of a changed area. |
| 332 | changedAreas.push({ start: changedAreaStart, end: i - 1 }); |
| 333 | changedAreaStart = -1; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | // Handle the last changed area if it extends to the end. |
| 338 | if (changedAreaStart !== -1) { |
| 339 | changedAreas.push({ start: changedAreaStart, end: diffLines.length - 1 }); |
| 340 | } |
| 341 | |
| 342 | return changedAreas; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Count the number of lines in the old content (excluding "new" lines). |