patch 9.1.0180: Cursor pos wrong when double-width chars are concealed
Problem: Cursor pos wrong when double-width chars are concealed.
Solution: Advance one more virtual column for a double-width char.
Run some tests with both 'wrap' and 'nowrap' (zeertzjq).
closes: #14197
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/testdir/test_conceal.vim b/src/testdir/test_conceal.vim
index 7080fdd..1cc08fc 100644
--- a/src/testdir/test_conceal.vim
+++ b/src/testdir/test_conceal.vim
@@ -441,7 +441,7 @@
call test_setmouse(1, 19)
call feedkeys("\<LeftMouse>", "tx")
call assert_equal([0, 1, 23, 0, 23], getcurpos())
- " click after end of line puts cursor there without 'virtualedit'
+ " click after end of line puts cursor there with 'virtualedit'
call test_setmouse(1, 20)
call feedkeys("\<LeftMouse>", "tx")
call assert_equal([0, 1, 24, 0, 24], getcurpos())
@@ -464,10 +464,9 @@
" Test that cursor is drawn at the correct column when it is after end of the
" line with 'virtualedit' and concealing.
-func Test_conceal_virtualedit_after_eol()
- CheckScreendump
-
- let code =<< trim [CODE]
+func Run_test_conceal_virtualedit_after_eol(wrap)
+ let code =<< trim eval [CODE]
+ let &wrap = {a:wrap}
call setline(1, 'abcdefgh|hidden|ijklmnpop')
syntax match test /|hidden|/ conceal
set conceallevel=2 concealcursor=n virtualedit=all
@@ -489,12 +488,17 @@
call StopVimInTerminal(buf)
endfunc
-" Same as Test_conceal_virtualedit_after_eol(), but with 'rightleft' set.
-func Test_conceal_virtualedit_after_eol_rightleft()
- CheckFeature rightleft
+func Test_conceal_virtualedit_after_eol()
CheckScreendump
- let code =<< trim [CODE]
+ call Run_test_conceal_virtualedit_after_eol(1)
+ call Run_test_conceal_virtualedit_after_eol(0)
+endfunc
+
+" Same as Run_test_conceal_virtualedit_after_eol(), but with 'rightleft'.
+func Run_test_conceal_virtualedit_after_eol_rightleft(wrap)
+ let code =<< trim eval [CODE]
+ let &wrap = {a:wrap}
call setline(1, 'abcdefgh|hidden|ijklmnpop')
syntax match test /|hidden|/ conceal
set conceallevel=2 concealcursor=n virtualedit=all rightleft
@@ -516,4 +520,66 @@
call StopVimInTerminal(buf)
endfunc
+func Test_conceal_virtualedit_after_eol_rightleft()
+ CheckFeature rightleft
+ CheckScreendump
+
+ call Run_test_conceal_virtualedit_after_eol_rightleft(1)
+ call Run_test_conceal_virtualedit_after_eol_rightleft(0)
+endfunc
+
+" Test that cursor position is correct when double-width chars are concealed.
+func Run_test_conceal_double_width(wrap)
+ let code =<< trim eval [CODE]
+ let &wrap = {a:wrap}
+ call setline(1, ['aaaaa口=口bbbbb口=口ccccc', 'foobar'])
+ syntax match test /口=口/ conceal cchar=β
+ set conceallevel=2 concealcursor=n colorcolumn=30
+ normal! $
+ [CODE]
+ call writefile(code, 'XTest_conceal_double_width', 'D')
+ let buf = RunVimInTerminal('-S XTest_conceal_double_width', {'rows': 4})
+ call VerifyScreenDump(buf, 'Test_conceal_double_width_1', {})
+ call term_sendkeys(buf, "gM")
+ call VerifyScreenDump(buf, 'Test_conceal_double_width_2', {})
+ call term_sendkeys(buf, ":set conceallevel=3\<CR>")
+ call VerifyScreenDump(buf, 'Test_conceal_double_width_3', {})
+ call term_sendkeys(buf, "$")
+ call VerifyScreenDump(buf, 'Test_conceal_double_width_4', {})
+
+ " clean up
+ call StopVimInTerminal(buf)
+endfunc
+
+func Test_conceal_double_width()
+ CheckScreendump
+
+ call Run_test_conceal_double_width(1)
+ call Run_test_conceal_double_width(0)
+endfunc
+
+" Test that line wrapping is correct when double-width chars are concealed.
+func Test_conceal_double_width_wrap()
+ CheckScreendump
+
+ let code =<< trim [CODE]
+ call setline(1, 'aaaaaaaaaa口=口bbbbbbbbbb口=口cccccccccc')
+ syntax match test /口=口/ conceal cchar=β
+ set conceallevel=2 concealcursor=n
+ normal! $
+ [CODE]
+ call writefile(code, 'XTest_conceal_double_width_wrap', 'D')
+ let buf = RunVimInTerminal('-S XTest_conceal_double_width_wrap', {'rows': 4, 'cols': 20})
+ call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_1', {})
+ call term_sendkeys(buf, "gM")
+ call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_2', {})
+ call term_sendkeys(buf, ":set conceallevel=3\<CR>")
+ call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_3', {})
+ call term_sendkeys(buf, "$")
+ call VerifyScreenDump(buf, 'Test_conceal_double_width_wrap_4', {})
+
+ " clean up
+ call StopVimInTerminal(buf)
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab