Skip to content

Commit da22b8c

Browse files
committed
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Problem: "icase" of 'diffopt' is not used for highlighting differences. Solution: Also use "icase". (Rick Howe)
1 parent dada6d2 commit da22b8c

3 files changed

Lines changed: 59 additions & 8 deletions

File tree

src/diff.c

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,40 @@ diffopt_horizontal(void)
19491949
return (diff_flags & DIFF_HORIZONTAL) != 0;
19501950
}
19511951

1952+
/*
1953+
* Compare the characters at "p1" and "p2". If they are equal (possibly
1954+
* ignoring case) return TRUE and set "len" to the number of bytes.
1955+
*/
1956+
static int
1957+
diff_equal_char(char_u *p1, char_u *p2, int *len)
1958+
{
1959+
#ifdef FEAT_MBYTE
1960+
int l = (*mb_ptr2len)(p1);
1961+
1962+
if (l != (*mb_ptr2len)(p2))
1963+
return FALSE;
1964+
if (l > 1)
1965+
{
1966+
if (STRNCMP(p1, p2, l) != 0
1967+
&& (!enc_utf8
1968+
|| !(diff_flags & DIFF_ICASE)
1969+
|| utf_fold(utf_ptr2char(p1))
1970+
!= utf_fold(utf_ptr2char(p2))))
1971+
return FALSE;
1972+
*len = l;
1973+
}
1974+
else
1975+
#endif
1976+
{
1977+
if ((*p1 != *p2)
1978+
&& (!(diff_flags & DIFF_ICASE)
1979+
|| TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2)))
1980+
return FALSE;
1981+
*len = 1;
1982+
}
1983+
return TRUE;
1984+
}
1985+
19521986
/*
19531987
* Find the difference within a changed line.
19541988
* Returns TRUE if the line was added, no other buffer has it.
@@ -1969,6 +2003,10 @@ diff_find_change(
19692003
int idx;
19702004
int off;
19712005
int added = TRUE;
2006+
#ifdef FEAT_MBYTE
2007+
char_u *p1, *p2;
2008+
int l;
2009+
#endif
19722010

19732011
/* Make a copy of the line, the next ml_get() will invalidate it. */
19742012
line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE));
@@ -2017,10 +2055,11 @@ diff_find_change(
20172055
}
20182056
else
20192057
{
2020-
if (line_org[si_org] != line_new[si_new])
2058+
if (!diff_equal_char(line_org + si_org, line_new + si_new,
2059+
&l))
20212060
break;
2022-
++si_org;
2023-
++si_new;
2061+
si_org += l;
2062+
si_new += l;
20242063
}
20252064
}
20262065
#ifdef FEAT_MBYTE
@@ -2056,10 +2095,16 @@ diff_find_change(
20562095
}
20572096
else
20582097
{
2059-
if (line_org[ei_org] != line_new[ei_new])
2098+
p1 = line_org + ei_org;
2099+
p2 = line_new + ei_new;
2100+
#ifdef FEAT_MBYTE
2101+
p1 -= (*mb_head_off)(line_org, p1);
2102+
p2 -= (*mb_head_off)(line_new, p2);
2103+
#endif
2104+
if (!diff_equal_char(p1, p2, &l))
20602105
break;
2061-
--ei_org;
2062-
--ei_new;
2106+
ei_org -= l;
2107+
ei_new -= l;
20632108
}
20642109
}
20652110
if (*endp < ei_org)

src/testdir/test_diffmode.vim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ func Test_diffopt_icase()
280280
set diffopt=icase,foldcolumn:0
281281

282282
e one
283-
call setline(1, ['One', 'Two', 'Three', 'Four'])
283+
call setline(1, ['One', 'Two', 'Three', 'Four', 'Fi#ve'])
284284
redraw
285285
let normattr = screenattr(1, 1)
286286
diffthis
287287

288288
botright vert new two
289-
call setline(1, ['one', 'TWO', 'Three ', 'Four'])
289+
call setline(1, ['one', 'TWO', 'Three ', 'Four', 'fI=VE'])
290290
diffthis
291291

292292
redraw
@@ -295,6 +295,10 @@ func Test_diffopt_icase()
295295
call assert_notequal(normattr, screenattr(3, 1))
296296
call assert_equal(normattr, screenattr(4, 1))
297297

298+
let dtextattr = screenattr(5, 3)
299+
call assert_notequal(dtextattr, screenattr(5, 1))
300+
call assert_notequal(dtextattr, screenattr(5, 5))
301+
298302
diffoff!
299303
%bwipe!
300304
set diffopt&

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1037,
772774
/**/
773775
1036,
774776
/**/

0 commit comments

Comments
 (0)