From 4737fc2485d6d5b311e5b3c6f7bac096fc30412b Mon Sep 17 00:00:00 2001 From: Itamar Date: Sun, 6 Feb 2022 22:54:20 +0200 Subject: [PATCH] LibDiff: Flush leftover hunks at the end This change makes sure that we arrive at the end of the "DP-matrix" and flush any leftover hunks to get a complete diff result. --- Userland/Libraries/LibDiff/Generator.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Userland/Libraries/LibDiff/Generator.cpp b/Userland/Libraries/LibDiff/Generator.cpp index 3224ea6525..43bdee9207 100644 --- a/Userland/Libraries/LibDiff/Generator.cpp +++ b/Userland/Libraries/LibDiff/Generator.cpp @@ -106,6 +106,16 @@ Vector from_text(StringView old_text, StringView new_text) flush_hunk(); } } + + while (i < old_lines.size() && new_lines.size() > 0) { + update_hunk(i, 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 + ++j; + } + flush_hunk(); return hunks;