vim-patch:8.1.1868: multi-byte chars in 'listchars' fail with 'linebreak' set

Problem:    Multibyte characters in 'listchars' don't work correctly if
            'linebreak' is also enabled. (Martin Tournoij)
Solution:   Make it work correctly. (Christian Brabandt, closes vim/vim#4822,
            closes vim/vim#4812)
69cbbecf54
This commit is contained in:
Jan Edmund Lazo 2020-02-20 00:41:06 -05:00
parent 9897ad3606
commit 13b6f7a806
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15
2 changed files with 33 additions and 6 deletions

View File

@ -3647,8 +3647,9 @@ win_line (
tab_len += n_extra - tab_len; tab_len += n_extra - tab_len;
} }
/* if n_extra > 0, it gives the number of chars to use for // if n_extra > 0, it gives the number of chars
* a tab, else we need to calculate the width for a tab */ // to use for a tab, else we need to calculate the width
// for a tab
int len = (tab_len * mb_char2len(wp->w_p_lcs_chars.tab2)); int len = (tab_len * mb_char2len(wp->w_p_lcs_chars.tab2));
if (n_extra > 0) { if (n_extra > 0) {
len += n_extra - tab_len; len += n_extra - tab_len;
@ -3660,10 +3661,16 @@ win_line (
xfree(p_extra_free); xfree(p_extra_free);
p_extra_free = p; p_extra_free = p;
for (i = 0; i < tab_len; i++) { for (i = 0; i < tab_len; i++) {
utf_char2bytes(wp->w_p_lcs_chars.tab2, p); int lcs = wp->w_p_lcs_chars.tab2;
p += mb_char2len(wp->w_p_lcs_chars.tab2);
n_extra += mb_char2len(wp->w_p_lcs_chars.tab2) // if tab3 is given, need to change the char
- (saved_nextra > 0 ? 1: 0); // for tab
if (wp->w_p_lcs_chars.tab3 && i == tab_len - 1) {
lcs = wp->w_p_lcs_chars.tab3;
}
utf_char2bytes(lcs, p);
p += mb_char2len(lcs);
n_extra += mb_char2len(lcs) - (saved_nextra > 0 ? 1 : 0);
} }
p_extra = p_extra_free; p_extra = p_extra_free;

View File

@ -58,6 +58,26 @@ func Test_listchars()
call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
endfor endfor
" tab with 3rd character and linebreak set
set listchars-=tab:<=>
set listchars+=tab:<·>
set linebreak
let expected = [
\ '<······>aa<····>$',
\ '..bb<··>--$',
\ '...cccc>-$',
\ 'dd........ee--<>$',
\ '-$'
\ ]
redraw!
for i in range(1, 5)
call cursor(i, 1)
call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$')))
endfor
set nolinebreak
set listchars-=tab:<·>
set listchars+=tab:<=>
set listchars-=trail:- set listchars-=trail:-
let expected = [ let expected = [
\ '<======>aa<====>$', \ '<======>aa<====>$',