Skip to content

Commit c6cd840

Browse files
committed
patch 8.0.0518: bad fold text when a multi-byte char has a zero byte
Problem: Storing a zero byte from a multi-byte character causes fold text to show up wrong. Solution: Avoid putting zero in ScreenLines. (Christian Brabandt, closes #1567)
1 parent b6fa30c commit c6cd840

3 files changed

Lines changed: 44 additions & 19 deletions

File tree

src/screen.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,12 +2697,15 @@ fold_line(
26972697
{
26982698
ScreenLinesUC[off + col] = fill_fold;
26992699
ScreenLinesC[0][off + col] = 0;
2700+
ScreenLines[off + col] = 0x80; /* avoid storing zero */
27002701
}
27012702
else
27022703
ScreenLinesUC[off + col] = 0;
2704+
col++;
27032705
}
2706+
else
27042707
#endif
2705-
ScreenLines[off + col++] = fill_fold;
2708+
ScreenLines[off + col++] = fill_fold;
27062709
}
27072710

27082711
if (text != buf)

src/testdir/test_display.vim

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ if !has('gui_running') && has('unix')
33
set term=ansi
44
endif
55

6-
function! s:screenline(lnum, nr) abort
7-
let line = []
8-
for j in range(a:nr)
9-
for c in range(1, winwidth(0))
10-
call add(line, nr2char(screenchar(a:lnum+j, c)))
11-
endfor
12-
call add(line, "\n")
13-
endfor
14-
return join(line, '')
15-
endfunction
6+
source view_util.vim
167

17-
function! Test_display_foldcolumn()
8+
func! Test_display_foldcolumn()
9+
if !has("folding")
10+
return
11+
endif
1812
new
1913
vnew
2014
vert resize 25
@@ -23,17 +17,43 @@ function! Test_display_foldcolumn()
2317

2418
1put='e more noise blah blah‚ more stuff here'
2519

26-
let expect = "e more noise blah blah<82\n> more stuff here \n"
20+
let expect = [
21+
\ "e more noise blah blah<82",
22+
\ "> more stuff here "
23+
\ ]
2724

2825
call cursor(2, 1)
2926
norm! zt
30-
redraw!
31-
call assert_equal(expect, s:screenline(1,2))
27+
let lines=ScreenLines([1,2], winwidth(0))
28+
call assert_equal(expect, lines)
3229
set fdc=2
33-
redraw!
34-
let expect = " e more noise blah blah<\n 82> more stuff here \n"
35-
call assert_equal(expect, s:screenline(1,2))
30+
let lines=ScreenLines([1,2], winwidth(0))
31+
let expect = [
32+
\ " e more noise blah blah<",
33+
\ " 82> more stuff here "
34+
\ ]
35+
call assert_equal(expect, lines)
3636

3737
quit!
3838
quit!
39-
endfunction
39+
endfunc
40+
41+
func! Test_display_foldtext_mbyte()
42+
if !has("folding") || !has("multi_byte")
43+
return
44+
endif
45+
call NewWindow(10, 40)
46+
call append(0, range(1,20))
47+
exe "set foldmethod=manual foldtext=foldtext() fillchars=fold:\u2500,vert:\u2502 fdc=2"
48+
call cursor(2, 1)
49+
norm! zf13G
50+
let lines=ScreenLines([1,3], winwidth(0)+1)
51+
let expect=[
52+
\ " 1 \u2502",
53+
\ "+ +-- 12 lines: 2". repeat("\u2500", 23). "\u2502",
54+
\ " 14 \u2502",
55+
\ ]
56+
call assert_equal(expect, lines)
57+
set foldtext& fillchars& foldmethod& fdc&
58+
bw!
59+
endfunc

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
518,
767769
/**/
768770
517,
769771
/**/

0 commit comments

Comments
 (0)