Skip to content

Fix #83 - Lines not properly marked #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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