Skip to content

Commit 4c1bb37

Browse files
committed
try to fix "Wrong highlight area in Chinese"
with phalcongelist@445c563
1 parent 09b54e4 commit 4c1bb37

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lib/Diff/Renderer/Html/Array.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,17 @@ public function render()
126126

127127
list($start, $end) = $this->getChangeExtent($fromLine, $toLine);
128128
if($start != 0 || $end != 0) {
129-
$last = $end + strlen($fromLine);
130-
$fromLine = $this->mb_substr_replace($fromLine, "\0", $start, 0);
131-
$fromLine = $this->mb_substr_replace($fromLine, "\1", $last + 1, 0);
132-
$last = $end + strlen($toLine);
133-
$toLine = $this->mb_substr_replace($toLine, "\0", $start, 0);
134-
$toLine = $this->mb_substr_replace($toLine, "\1", $last + 1, 0);
129+
$realEnd = mb_strlen($fromLine) + $end;
130+
131+
$fromLine = mb_substr($fromLine, 0, $start) . "\0" .
132+
mb_substr($fromLine, $start, $realEnd - $start) . "\1" . mb_substr($fromLine, $realEnd);
133+
134+
$realEnd = mb_strlen($toLine) + $end;
135+
136+
$toLine = mb_substr($toLine, 0, $start) .
137+
"\0" . mb_substr($toLine, $start, $realEnd - $start) . "\1" .
138+
mb_substr($toLine, $realEnd);
139+
135140
$a[$i1 + $i] = $fromLine;
136141
$b[$j1 + $i] = $toLine;
137142
}
@@ -193,13 +198,13 @@ public function render()
193198
private function getChangeExtent($fromLine, $toLine)
194199
{
195200
$start = 0;
196-
$limit = min(strlen($fromLine), strlen($toLine));
197-
while($start < $limit && $fromLine{$start} == $toLine{$start}) {
201+
$limit = min(mb_strlen($fromLine), mb_strlen($toLine));
202+
while($start < $limit && mb_substr($fromLine, $start, 1) == mb_substr($toLine, $start, 1)) {
198203
++$start;
199204
}
200205
$end = -1;
201206
$limit = $limit - $start;
202-
while(-$end <= $limit && substr($fromLine, $end, 1) == substr($toLine, $end, 1)) {
207+
while(-$end <= $limit && mb_substr($fromLine, $end, 1) == mb_substr($toLine, $end, 1)) {
203208
--$end;
204209
}
205210
return array(

lib/Diff/SequenceMatcher.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ class Diff_SequenceMatcher
6767
*/
6868
private $b2j = array();
6969

70-
private $juncDict = array();
71-
7270
private $options = array();
7371

7472
private $opCodes;
@@ -221,7 +219,7 @@ private function chainB()
221219
*/
222220
private function isBJunk($b)
223221
{
224-
if(isset($this->juncDict[$b])) {
222+
if(isset($this->junkDict[$b])) {
225223
return true;
226224
}
227225

0 commit comments

Comments
 (0)