From 6fcafe114f58843a0a19d7b053bd7a752f27b41d Mon Sep 17 00:00:00 2001 From: DigiLive Date: Fri, 4 Dec 2020 10:29:20 +0100 Subject: [PATCH] Fix #83 - Lines not properly marked If a line is different at the other version from the first to the last character, the line isn't marked when inlineMarking is set to CHANGE_LEVEL_LINE. --- lib/jblond/Diff/Renderer/MainRenderer.php | 38 +++++++++++------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/jblond/Diff/Renderer/MainRenderer.php b/lib/jblond/Diff/Renderer/MainRenderer.php index bff743e..f0b579a 100644 --- a/lib/jblond/Diff/Renderer/MainRenderer.php +++ b/lib/jblond/Diff/Renderer/MainRenderer.php @@ -310,26 +310,24 @@ private function markOuterChange(array &$oldText, array &$newText, int $startOld // Determine the start and end position of the line difference. [$start, $end] = $this->getOuterChange($oldString, $newString); - if ($start != 0 || $end != 0) { - // Changes between the lines exist. - // Add markers around the changed character sequence in the old string. - $sequenceEnd = mb_strlen($oldString) + $end; - $oldString = - mb_substr($oldString, 0, $start) . "\0" . - mb_substr($oldString, $start, $sequenceEnd - $start) . "\1" . - mb_substr($oldString, $sequenceEnd); - - // Add markers around the changed character sequence in the new string. - $sequenceEnd = mb_strlen($newString) + $end; - $newString = - mb_substr($newString, 0, $start) . "\0" . - mb_substr($newString, $start, $sequenceEnd - $start) . "\1" . - mb_substr($newString, $sequenceEnd); - - // Overwrite the strings in the old and new text so the changed lines include the markers. - $oldText[$startOld + $iterator] = $oldString; - $newText[$startNew + $iterator] = $newString; - } + // Changes between the lines exist. + // Add markers around the changed character sequence in the old string. + $sequenceEnd = mb_strlen($oldString) + $end; + $oldString + = mb_substr($oldString, 0, $start) . "\0" . + mb_substr($oldString, $start, $sequenceEnd - $start) . "\1" . + mb_substr($oldString, $sequenceEnd); + + // Add markers around the changed character sequence in the new string. + $sequenceEnd = mb_strlen($newString) + $end; + $newString + = mb_substr($newString, 0, $start) . "\0" . + mb_substr($newString, $start, $sequenceEnd - $start) . "\1" . + mb_substr($newString, $sequenceEnd); + + // Overwrite the strings in the old and new text so the changed lines include the markers. + $oldText[$startOld + $iterator] = $oldString; + $newText[$startNew + $iterator] = $newString; } }