otakustay/react-diff-view

Bug: For diff with context containing empty line the empty line is not shown

Closed this issue · 2 comments

For diffs with context around hunks (eg. using git diff -U1), if the context line below a diff is empty then the line is not shown.

The bug exists probably since v2.4.2 and is probably caused by trim method on the diff which removes the empty context line.

const diffText = normalizeDiffText(text.trim());

Example:

Older version of a file:

void foo() {

  if (cond)
    doSomething();
  // Below is empty line

}

New version of the file:

void foo() {

  if (cond) {
    doSomething();
    doSomethingNext();
  }
  // Below is still empty line

}

Diff gained by git diff -U1

diff --git a/a.c b/a.c
index ca1fe9c..e6f7947 100644
--- a/a.c
+++ b/a.c
@@ -2,5 +2,7 @@ void foo() {
 
-    if (cond)
+    if (cond) {
         doSomething();
-    // Below is empty line
+        doSomethingNext();
+    }
+    // Below is still empty line
 

Result of visualisaton using react-diff-view: (with missing context line below diff)
image

Expected result (v2.4.1): (with context line below diff)

image

Seems you are working on it, I'll wait for a PR, thanks

Solved by #216