1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09: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:
Daniel Bertalan 2022-02-25 22:06:54 +01:00 committed by Linus Groh
parent 7bd68c86d3
commit 4b4177f39c
Notes: sideshowbarker 2024-07-17 17:42:27 +09:00

View file

@ -107,12 +107,12 @@ Vector<Hunk> from_text(StringView old_text, StringView new_text)
}
}
while (i < old_lines.size() && new_lines.size() > 0) {
update_hunk(i, new_lines.size() - 1, Direction::Right); // Remove a line
while (i < old_lines.size()) {
update_hunk(i, new_lines.is_empty() ? 0 : new_lines.size() - 1, Direction::Right); // Remove a line
++i;
}
while (j < new_lines.size() && old_lines.size() > 0) {
update_hunk(old_lines.size() - 1, j, Direction::Down); // Add a line
while (j < new_lines.size()) {
update_hunk(old_lines.is_empty() ? 0 : old_lines.size() - 1, j, Direction::Down); // Add a line
++j;
}