Skip to content

Commit

Permalink
Fix #83 - Lines not properly marked
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DigiLive committed Dec 4, 2020
1 parent 0bd0bd2 commit 6fcafe1
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions lib/jblond/Diff/Renderer/MainRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 6fcafe1

Please sign in to comment.