vim-patch:8.1.1078: when 'listchars' is set a composing char on a space is wrong

Problem:    When 'listchars' is set a composing char on a space is wrong.
Solution:   Separate handling a non-breaking space and a space. (Yasuhiro
            Matsumoto, closes vim/vim#4046)
5f8069bbf5
This commit is contained in:
zeertzjq 2021-09-19 13:13:44 +08:00
parent 963474321b
commit 32663b0f7e
2 changed files with 45 additions and 18 deletions

View File

@ -3581,24 +3581,28 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
}
// 'list': change char 160 to 'nbsp' and space to 'space'.
if (wp->w_p_list
&& (((c == 160
|| (mb_utf8 && (mb_c == 160 || mb_c == 0x202f)))
&& curwin->w_p_lcs_chars.nbsp)
|| (c == ' ' && curwin->w_p_lcs_chars.space
&& ptr - line >= leadcol
&& ptr - line <= trailcol))) {
c = (c == ' ') ? wp->w_p_lcs_chars.space : wp->w_p_lcs_chars.nbsp;
n_attr = 1;
extra_attr = win_hl_attr(wp, HLF_0);
saved_attr2 = char_attr; // save current attr
mb_c = c;
if (utf_char2len(c) > 1) {
mb_utf8 = true;
u8cc[0] = 0;
c = 0xc0;
} else {
mb_utf8 = false;
if (wp->w_p_list) {
if ((c == 160 || (mb_utf8 && (mb_c == 160 || mb_c == 0x202f)))
&& wp->w_p_lcs_chars.nbsp) {
c = wp->w_p_lcs_chars.nbsp;
mb_c = c;
if (utf_char2len(c) > 1) {
mb_utf8 = true;
u8cc[0] = 0;
c = 0xc0;
} else {
mb_utf8 = false;
}
} else if (c == ' '
&& wp->w_p_lcs_chars.space
&& ptr - line >= leadcol
&& ptr - line <= trailcol) {
c = wp->w_p_lcs_chars.space;
if (mb_utf8 == false) {
n_attr = 1;
extra_attr = win_hl_attr(wp, HLF_0);
saved_attr2 = char_attr; // save current attr
}
}
}

View File

@ -181,3 +181,26 @@ func Test_listchars()
enew!
set listchars& ff&
endfunc
func Test_listchars_composing()
enew!
let oldencoding=&encoding
set encoding=utf-8
set ff=unix
set list
set listchars=eol:$,space:_
call append(0, [
\ " \u3099 \u309A"
\ ])
let expected = [
\ "_ \u3099^I \u309A$"
\ ]
redraw!
call cursor(1, 1)
let got = ScreenLinesUtf8(1, virtcol('$'))
bw!
call assert_equal(expected, got)
let &encoding=oldencoding
set listchars& ff&
endfunction