mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 14:07:43 +00:00
LibDiff: Generate hunks for new/deleted files
Previously we would fail to generate any hunks if the old or the new file was empty. We now do, with the original/target line index set to 0, as specified by POSIX.
This commit is contained in:
parent
7bd68c86d3
commit
4b4177f39c
1 changed files with 4 additions and 4 deletions
|
@ -107,12 +107,12 @@ Vector<Hunk> from_text(StringView old_text, StringView new_text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (i < old_lines.size() && new_lines.size() > 0) {
|
while (i < old_lines.size()) {
|
||||||
update_hunk(i, new_lines.size() - 1, Direction::Right); // Remove a line
|
update_hunk(i, new_lines.is_empty() ? 0 : new_lines.size() - 1, Direction::Right); // Remove a line
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
while (j < new_lines.size() && old_lines.size() > 0) {
|
while (j < new_lines.size()) {
|
||||||
update_hunk(old_lines.size() - 1, j, Direction::Down); // Add a line
|
update_hunk(old_lines.is_empty() ? 0 : old_lines.size() - 1, j, Direction::Down); // Add a line
|
||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue