Mercurial > vim
changeset 34559:ef55fe2ac8be v9.1.0180
patch 9.1.0180: Cursor pos wrong when double-width chars are concealed
Commit: https://github.com/vim/vim/commit/010e1539d67442cc69a97bef6453efaf849d0db3
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu Mar 14 18:22:17 2024 +0100
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>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 14 Mar 2024 18:30:05 +0100 |
parents | 4fcffe60b441 |
children | 8b94adf4474a |
files | src/drawline.c src/testdir/dumps/Test_conceal_double_width_1.dump src/testdir/dumps/Test_conceal_double_width_2.dump src/testdir/dumps/Test_conceal_double_width_3.dump src/testdir/dumps/Test_conceal_double_width_4.dump src/testdir/dumps/Test_conceal_double_width_wrap_1.dump src/testdir/dumps/Test_conceal_double_width_wrap_2.dump src/testdir/dumps/Test_conceal_double_width_wrap_3.dump src/testdir/dumps/Test_conceal_double_width_wrap_4.dump src/testdir/test_conceal.vim src/version.c |
diffstat | 11 files changed, 137 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/drawline.c +++ b/src/drawline.c @@ -3225,7 +3225,7 @@ win_line( // Make sure, the highlighting for the tab char will be // correctly set further below (effectively reverts the - // FIX_FOR_BOGSUCOLS macro). + // FIX_FOR_BOGUSCOLS macro). if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list && wp->w_lcs_chars.tab1) tab_len += vc_saved; @@ -3494,6 +3494,21 @@ win_line( else c = ' '; + if (has_mbyte && (*mb_char2cells)(mb_c) > 1) + // When the first char to be concealed is double-width, + // need to advance one more virtual column. + wlv.n_extra++; + + mb_c = c; + if (enc_utf8 && utf_char2len(c) > 1) + { + mb_utf8 = TRUE; + u8cc[0] = 0; + c = 0xc0; + } + else + mb_utf8 = FALSE; // don't draw as UTF-8 + prev_syntax_id = syntax_seqnr; if (wlv.n_extra > 0) @@ -3522,15 +3537,6 @@ win_line( is_concealing = TRUE; skip_cells = 1; } - mb_c = c; - if (enc_utf8 && utf_char2len(c) > 1) - { - mb_utf8 = TRUE; - u8cc[0] = 0; - c = 0xc0; - } - else - mb_utf8 = FALSE; // don't draw as UTF-8 } else { @@ -3990,10 +3996,21 @@ win_line( #ifdef FEAT_CONCEAL else if (wp->w_p_cole > 0 && is_concealing) { + int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1; + --skip_cells; ++wlv.vcol_off_co; + if (concealed_wide) + { + // When a double-width char is concealed, + // need to advance one more virtual column. + ++wlv.vcol; + ++wlv.vcol_off_co; + } + if (wlv.n_extra > 0) wlv.vcol_off_co += wlv.n_extra; + if (wp->w_p_wrap) { // Special voodoo required if 'wrap' is on. @@ -4026,8 +4043,7 @@ win_line( n_attr = 0; } - - if (has_mbyte && (*mb_char2cells)(mb_c) > 1) + if (concealed_wide) { // Need to fill two screen columns. # ifdef FEAT_RIGHTLEFT
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_double_width_1.dump @@ -0,0 +1,4 @@ +|a+0&#ffffff0@4|β+0#e0e0e08#6c6c6c255|b+0#0000000#ffffff0@4|β+0#e0e0e08#6c6c6c255|c+0#0000000#ffffff0@3>c| @11| +0&#ffd7d7255| +0&#ffffff0@44 +|f|o@1|b|a|r| @22| +0&#ffd7d7255| +0&#ffffff0@44 +|~+0#4040ff13&| @73 +| +0#0000000&@56|1|,|2|9|-|2|5| @6|A|l@1|
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_double_width_2.dump @@ -0,0 +1,4 @@ +|a+0&#ffffff0@4|β+0#e0e0e08#6c6c6c255|b+0#0000000#ffffff0@1>b@2|β+0#e0e0e08#6c6c6c255|c+0#0000000#ffffff0@4| @11| +0&#ffd7d7255| +0&#ffffff0@44 +|f|o@1|b|a|r| @22| +0&#ffd7d7255| +0&#ffffff0@44 +|~+0#4040ff13&| @73 +| +0#0000000&@56|1|,|1|5|-|1|3| @6|A|l@1|
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_double_width_3.dump @@ -0,0 +1,4 @@ +|a+0&#ffffff0@4|b@1>b@2|c@4| @13| +0&#ffd7d7255| +0&#ffffff0@44 +|f|o@1|b|a|r| @22| +0&#ffd7d7255| +0&#ffffff0@44 +|~+0#4040ff13&| @73 +|:+0#0000000&|s|e|t| |c|o|n|c|e|a|l@1|e|v|e|l|=|3| @37|1|,|1|5|-|1|3| @6|A|l@1|
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_double_width_4.dump @@ -0,0 +1,4 @@ +|a+0&#ffffff0@4|b@4|c@3>c| @13| +0&#ffd7d7255| +0&#ffffff0@44 +|f|o@1|b|a|r| @22| +0&#ffd7d7255| +0&#ffffff0@44 +|~+0#4040ff13&| @73 +|:+0#0000000&|s|e|t| |c|o|n|c|e|a|l@1|e|v|e|l|=|3| @37|1|,|2|9|-|2|5| @6|A|l@1|
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_double_width_wrap_1.dump @@ -0,0 +1,4 @@ +|a+0&#ffffff0@9|β+0#e0e0e08#6c6c6c255|b+0#0000000#ffffff0@4| @3 +|b@4|β+0#e0e0e08#6c6c6c255|c+0#0000000#ffffff0@8>c| @3 +|~+0#4040ff13&| @18 +| +0#0000000&@9|1|,|4@1|-|4|0| @2
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_double_width_wrap_2.dump @@ -0,0 +1,4 @@ +|a+0&#ffffff0@9|β+0#e0e0e08#6c6c6c255|b+0#0000000#ffffff0@4| @3 +>b@4|β+0#e0e0e08#6c6c6c255|c+0#0000000#ffffff0@9| @3 +|~+0#4040ff13&| @18 +| +0#0000000&@9|1|,|2|3|-|2|1| @2
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_double_width_wrap_3.dump @@ -0,0 +1,4 @@ +|a+0&#ffffff0@9|b@4| @4 +>b@4|c@9| @4 +|~+0#4040ff13&| @18 +|:+0#0000000&|s|e|t| |c|o|n|c|e|1|,|2|3|-|2|1| @2
new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_double_width_wrap_4.dump @@ -0,0 +1,4 @@ +|a+0&#ffffff0@9|b@4| @4 +|b@4|c@8>c| @4 +|~+0#4040ff13&| @18 +|:+0#0000000&| @8|1|,|4@1|-|4|0| @2
--- a/src/testdir/test_conceal.vim +++ b/src/testdir/test_conceal.vim @@ -441,7 +441,7 @@ func Test_conceal_mouse_click() 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 @@ endfunc " 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 @@ func Test_conceal_virtualedit_after_eol( 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 @@ func Test_conceal_virtualedit_after_eol_ 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