From 963474321bcc02a5698c40b4677cd36ab8d4cebc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 19 Sep 2021 13:13:44 +0800 Subject: vim-patch:8.1.1071: cannot get composing characters from the screen Problem: Cannot get composing characters from the screen. Solution: Add screenchars() and screenstring(). (partly by Ozaki Kiichi, closes vim/vim#4059) https://github.com/vim/vim/commit/2912abb3a2fd72074e3901c8ae1d4a77ce764675 --- src/nvim/testdir/test_utf8.vim | 35 +++++++++++++++++++++++++++++++++++ src/nvim/testdir/view_util.vim | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index c51fb3a759..acf15e0e28 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -1,5 +1,6 @@ " Tests for Unicode manipulations +source view_util.vim " Visual block Insert adjusts for multi-byte char func Test_visual_block_insert() @@ -61,6 +62,40 @@ func Test_getvcol() call assert_equal(2, virtcol("']")) endfunc +func Test_screenchar_utf8() + new + + " 1-cell, with composing characters + call setline(1, ["ABC\u0308"]) + redraw + call assert_equal([0x0041], screenchars(1, 1)) + call assert_equal([0x0042], screenchars(1, 2)) + call assert_equal([0x0043, 0x0308], screenchars(1, 3)) + call assert_equal("A", screenstring(1, 1)) + call assert_equal("B", screenstring(1, 2)) + call assert_equal("C\u0308", screenstring(1, 3)) + + " 2-cells, with composing characters + let text = "\u3042\u3044\u3046\u3099" + call setline(1, text) + redraw + call assert_equal([0x3042], screenchars(1, 1)) + call assert_equal([0], screenchars(1, 2)) + call assert_equal([0x3044], screenchars(1, 3)) + call assert_equal([0], screenchars(1, 4)) + call assert_equal([0x3046, 0x3099], screenchars(1, 5)) + + call assert_equal("\u3042", screenstring(1, 1)) + call assert_equal("", screenstring(1, 2)) + call assert_equal("\u3044", screenstring(1, 3)) + call assert_equal("", screenstring(1, 4)) + call assert_equal("\u3046\u3099", screenstring(1, 5)) + + call assert_equal([text . ' '], ScreenLinesUtf8(1, 8)) + + bwipe! +endfunc + func Test_list2str_str2list_utf8() " One Unicode codepoint let s = "\u3042\u3044" diff --git a/src/nvim/testdir/view_util.vim b/src/nvim/testdir/view_util.vim index 1def201a05..dd143c02c1 100644 --- a/src/nvim/testdir/view_util.vim +++ b/src/nvim/testdir/view_util.vim @@ -34,6 +34,25 @@ function! ScreenLines(lnum, width) abort return lines endfunction +" Get text on the screen, including composing characters. +" ScreenLines(lnum, width) or +" ScreenLines([start, end], width) +function! ScreenLinesUtf8(lnum, width) abort + redraw! + if type(a:lnum) == v:t_list + let start = a:lnum[0] + let end = a:lnum[1] + else + let start = a:lnum + let end = a:lnum + endif + let lines = [] + for l in range(start, end) + let lines += [join(map(range(1, a:width), 'screenstring(l, v:val)'), '')] + endfor + return lines +endfunction + function! ScreenAttrs(lnum, width) abort redraw! if type(a:lnum) == v:t_list -- cgit From 32663b0f7e5911a8bced6b65dfc43622aadba198 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 19 Sep 2021 13:13:44 +0800 Subject: 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) https://github.com/vim/vim/commit/5f8069bbf5d989936a2f4d7a76ae42434017e3a2 --- src/nvim/testdir/test_listchars.vim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_listchars.vim b/src/nvim/testdir/test_listchars.vim index 4cb609aaf0..191e2afdf1 100644 --- a/src/nvim/testdir/test_listchars.vim +++ b/src/nvim/testdir/test_listchars.vim @@ -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 -- cgit From c14dc616bf4a6121e49594c8f51c1fb197b2ac7f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 19 Sep 2021 13:13:44 +0800 Subject: vim-patch:8.1.1079: no need for a separate ScreenLinesUtf8() test function Problem: No need for a separate ScreenLinesUtf8() test function. Solution: Get the composing characters with ScreenLines(). https://github.com/vim/vim/commit/48aed0824e47147faf19fc235ad4bcf851584c9c --- src/nvim/testdir/test_utf8.vim | 2 +- src/nvim/testdir/view_util.vim | 20 +------------------- 2 files changed, 2 insertions(+), 20 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index acf15e0e28..735efac36d 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -91,7 +91,7 @@ func Test_screenchar_utf8() call assert_equal("", screenstring(1, 4)) call assert_equal("\u3046\u3099", screenstring(1, 5)) - call assert_equal([text . ' '], ScreenLinesUtf8(1, 8)) + call assert_equal([text . ' '], ScreenLines(1, 8)) bwipe! endfunc diff --git a/src/nvim/testdir/view_util.vim b/src/nvim/testdir/view_util.vim index dd143c02c1..1cdce21602 100644 --- a/src/nvim/testdir/view_util.vim +++ b/src/nvim/testdir/view_util.vim @@ -16,28 +16,10 @@ func Screenline(lnum) return matchstr(line, '^.\{-}\ze\s*$') endfunc -" ScreenLines(lnum, width) or -" ScreenLines([start, end], width) -function! ScreenLines(lnum, width) abort - redraw! - if type(a:lnum) == v:t_list - let start = a:lnum[0] - let end = a:lnum[1] - else - let start = a:lnum - let end = a:lnum - endif - let lines = [] - for l in range(start, end) - let lines += [join(map(range(1, a:width), 'nr2char(screenchar(l, v:val))'), '')] - endfor - return lines -endfunction - " Get text on the screen, including composing characters. " ScreenLines(lnum, width) or " ScreenLines([start, end], width) -function! ScreenLinesUtf8(lnum, width) abort +function! ScreenLines(lnum, width) abort redraw! if type(a:lnum) == v:t_list let start = a:lnum[0] -- cgit From 59e80c4dfcddeb9f20e175afbdb8f085ec5da985 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 19 Sep 2021 13:13:44 +0800 Subject: vim-patch:8.1.1110: composing chars on space wrong when 'listchars' is set Problem: Composing chars on space wrong when 'listchars' is set. Solution: Do not use "space" and "nbsp" entries of 'listchars' when there is a composing character. (Yee Cheng Chin, closes vim/vim#4197) https://github.com/vim/vim/commit/e5e4e22c1c15c8c22b14935affe969569acc8df9 --- src/nvim/testdir/test_listchars.vim | 41 +++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_listchars.vim b/src/nvim/testdir/test_listchars.vim index 191e2afdf1..b75eec3d2e 100644 --- a/src/nvim/testdir/test_listchars.vim +++ b/src/nvim/testdir/test_listchars.vim @@ -182,6 +182,33 @@ func Test_listchars() set listchars& ff& endfunc +" Test that unicode listchars characters get properly inserted +func Test_listchars_unicode() + enew! + let oldencoding=&encoding + set encoding=utf-8 + set ff=unix + + set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→ + set list + + let nbsp = nr2char(0xa0) + call append(0, [ + \ "a\tb c".nbsp."d" + \ ]) + let expected = [ + \ 'a←↔↔↔↔↔→b␣c≠d⇔' + \ ] + redraw! + call cursor(1, 1) + call assert_equal(expected, ScreenLines(1, virtcol('$'))) + let &encoding=oldencoding + enew! + set listchars& ff& +endfunction + +" Tests that space characters following composing character won't get replaced +" by listchars. func Test_listchars_composing() enew! let oldencoding=&encoding @@ -189,18 +216,20 @@ func Test_listchars_composing() set ff=unix set list - set listchars=eol:$,space:_ + set listchars=eol:$,space:_,nbsp:= + + let nbsp1 = nr2char(0xa0) + let nbsp2 = nr2char(0x202f) call append(0, [ - \ " \u3099 \u309A" + \ " \u3099\t \u309A".nbsp1.nbsp1."\u0302".nbsp2.nbsp2."\u0302", \ ]) let expected = [ - \ "_ \u3099^I \u309A$" + \ "_ \u3099^I \u309A=".nbsp1."\u0302=".nbsp2."\u0302$" \ ] redraw! call cursor(1, 1) - let got = ScreenLinesUtf8(1, virtcol('$')) - bw! - call assert_equal(expected, got) + call assert_equal(expected, ScreenLines(1, virtcol('$'))) let &encoding=oldencoding + enew! set listchars& ff& endfunction -- cgit From 177e87525ababda460cab77314ceb72801a3017f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 19 Sep 2021 13:13:44 +0800 Subject: vim-patch:8.2.2640: screenstring() returns non-existing composing characters Problem: screenstring() returns non-existing composing characters. Solution: Only use composing characters if there is a base character. https://github.com/vim/vim/commit/f1387285e2ebe5cb3688d729fc6fd01a169a76c1 --- src/nvim/testdir/test_listchars.vim | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_listchars.vim b/src/nvim/testdir/test_listchars.vim index b75eec3d2e..8fc1b519f4 100644 --- a/src/nvim/testdir/test_listchars.vim +++ b/src/nvim/testdir/test_listchars.vim @@ -146,7 +146,7 @@ func Test_listchars() set list " Non-breaking space let nbsp = nr2char(0xa0) - call append(0, [ ">".nbsp."<" ]) + call append(0, [ ">" .. nbsp .. "<" ]) let expected = '>X< ' @@ -193,12 +193,8 @@ func Test_listchars_unicode() set list let nbsp = nr2char(0xa0) - call append(0, [ - \ "a\tb c".nbsp."d" - \ ]) - let expected = [ - \ 'a←↔↔↔↔↔→b␣c≠d⇔' - \ ] + call append(0, ["a\tb c" .. nbsp .. "d"]) + let expected = ['a←↔↔↔↔↔→b␣c≠d⇔'] redraw! call cursor(1, 1) call assert_equal(expected, ScreenLines(1, virtcol('$'))) @@ -221,10 +217,10 @@ func Test_listchars_composing() let nbsp1 = nr2char(0xa0) let nbsp2 = nr2char(0x202f) call append(0, [ - \ " \u3099\t \u309A".nbsp1.nbsp1."\u0302".nbsp2.nbsp2."\u0302", + \ " \u3099\t \u309A" .. nbsp1 .. nbsp1 .. "\u0302" .. nbsp2 .. nbsp2 .. "\u0302", \ ]) let expected = [ - \ "_ \u3099^I \u309A=".nbsp1."\u0302=".nbsp2."\u0302$" + \ "_ \u3099^I \u309A=" .. nbsp1 .. "\u0302=" .. nbsp2 .. "\u0302$" \ ] redraw! call cursor(1, 1) -- cgit From 51567db4b6740004698492ed8b8fa13b53d20b48 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 19 Sep 2021 13:13:44 +0800 Subject: vim-patch:8.2.3424: a sequence of spaces is hard to see in list mode Problem: A sequence of spaces is hard to see in list mode. Solution: Add the "multispace" option to 'listchars'. (closes vim/vim#8834) https://github.com/vim/vim/commit/f14b8ba1373f569705cb80419248054100b02360 --- src/nvim/testdir/test_listchars.vim | 142 +++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_listchars.vim b/src/nvim/testdir/test_listchars.vim index 8fc1b519f4..8a1393a45d 100644 --- a/src/nvim/testdir/test_listchars.vim +++ b/src/nvim/testdir/test_listchars.vim @@ -140,6 +140,93 @@ func Test_listchars() call assert_equal(expected, split(execute("%list"), "\n")) + " Test multispace + normal ggdG + set listchars=eol:$ + set listchars+=multispace:yYzZ + set list + + call append(0, [ + \ ' ffff ', + \ ' i i gg', + \ ' h ', + \ ' j ', + \ ' 0 0 ', + \ ]) + + let expected = [ + \ 'yYzZffffyYzZ$', + \ 'yYi iyYzZygg$', + \ ' hyYzZyYzZyY$', + \ 'yYzZyYzZyYj $', + \ 'yYzZ0yY0yYzZ$', + \ '$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + call assert_equal(expected, split(execute("%list"), "\n")) + + " the last occurrence of 'multispace:' is used + set listchars+=space:x,multispace:XyY + + let expected = [ + \ 'XyYXffffXyYX$', + \ 'XyixiXyYXygg$', + \ 'xhXyYXyYXyYX$', + \ 'XyYXyYXyYXjx$', + \ 'XyYX0Xy0XyYX$', + \ '$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + call assert_equal(expected, split(execute("%list"), "\n")) + + set listchars+=lead:>,trail:< + + let expected = [ + \ '>>>>ffff<<<<$', + \ '>>ixiXyYXygg$', + \ '>h<<<<<<<<<<$', + \ '>>>>>>>>>>j<$', + \ '>>>>0Xy0<<<<$', + \ '$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + call assert_equal(expected, split(execute("%list"), "\n")) + + " removing 'multispace:' + set listchars-=multispace:XyY + set listchars-=multispace:yYzZ + + let expected = [ + \ '>>>>ffff<<<<$', + \ '>>ixixxxxxgg$', + \ '>h<<<<<<<<<<$', + \ '>>>>>>>>>>j<$', + \ '>>>>0xx0<<<<$', + \ '$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + call assert_equal(expected, split(execute("%list"), "\n")) + " test nbsp normal ggdG set listchars=nbsp:X,trail:Y @@ -189,20 +276,69 @@ func Test_listchars_unicode() set encoding=utf-8 set ff=unix - set listchars=eol:⇔,space:␣,nbsp:≠,tab:←↔→ + set listchars=eol:⇔,space:␣,multispace:≡≢≣,nbsp:≠,tab:←↔→ set list let nbsp = nr2char(0xa0) - call append(0, ["a\tb c" .. nbsp .. "d"]) - let expected = ['a←↔↔↔↔↔→b␣c≠d⇔'] + call append(0, [" a\tb c" .. nbsp .. "d "]) + let expected = ['≡≢≣≡≢≣≡≢a←↔↔↔↔↔→b␣c≠d≡≢⇔'] redraw! call cursor(1, 1) call assert_equal(expected, ScreenLines(1, virtcol('$'))) + + set listchars+=lead:⇨,trail:⇦ + let expected = ['⇨⇨⇨⇨⇨⇨⇨⇨a←↔↔↔↔↔→b␣c≠d⇦⇦⇔'] + redraw! + call cursor(1, 1) + call assert_equal(expected, ScreenLines(1, virtcol('$'))) + let &encoding=oldencoding enew! set listchars& ff& endfunction +func Test_listchars_invalid() + enew! + set ff=unix + + set listchars=eol:$ + set list + set ambiwidth=double + + " No colon + call assert_fails('set listchars=x', 'E474:') + call assert_fails('set listchars=x', 'E474:') + call assert_fails('set listchars=multispace', 'E474:') + + " Too short + call assert_fails('set listchars=space:', 'E474:') + call assert_fails('set listchars=tab:x', 'E474:') + call assert_fails('set listchars=multispace:', 'E474:') + + " One occurrence too short + call assert_fails('set listchars=space:,space:x', 'E474:') + call assert_fails('set listchars=space:x,space:', 'E474:') + call assert_fails('set listchars=tab:x,tab:xx', 'E474:') + call assert_fails('set listchars=tab:xx,tab:x', 'E474:') + call assert_fails('set listchars=multispace:,multispace:x', 'E474:') + call assert_fails('set listchars=multispace:x,multispace:', 'E474:') + + " Too long + call assert_fails('set listchars=space:xx', 'E474:') + call assert_fails('set listchars=tab:xxxx', 'E474:') + + " Has non-single width character + call assert_fails('set listchars=space:·', 'E474:') + call assert_fails('set listchars=tab:·x', 'E474:') + call assert_fails('set listchars=tab:x·', 'E474:') + call assert_fails('set listchars=tab:xx·', 'E474:') + call assert_fails('set listchars=multispace:·', 'E474:') + call assert_fails('set listchars=multispace:xxx·', 'E474:') + + enew! + set ambiwidth& listchars& ff& +endfunction + " Tests that space characters following composing character won't get replaced " by listchars. func Test_listchars_composing() -- cgit