From 5ff725fa94cc85e8dc4f92bb17e6dfd27aa0eaff Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Aug 2023 14:56:36 +0800 Subject: vim-patch:9.0.0048: cursor in wrong column with mouse click after concealed text Problem: Cursor in wrong column with mouse click after concealed text. Solution: Store the text column when drawing text. https://github.com/vim/vim/commit/b90818867c089d4987f1a48ee3666674826d6f4b Tests only. Code changes moved to the port of patch 9.0.1725. Co-authored-by: Bram Moolenaar --- test/old/testdir/test_conceal.vim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/old/testdir/test_conceal.vim b/test/old/testdir/test_conceal.vim index 63e17d8f2f..b9541b9e82 100644 --- a/test/old/testdir/test_conceal.vim +++ b/test/old/testdir/test_conceal.vim @@ -4,6 +4,7 @@ source check.vim CheckFeature conceal source screendump.vim +source view_util.vim func Test_conceal_two_windows() CheckScreendump @@ -334,4 +335,23 @@ func Test_conceal_eol() set nolist endfunc +func Test_conceal_mouse_click() + enew! + set mouse=a + setlocal conceallevel=2 concealcursor=nc + syn match Concealed "this" conceal + hi link Concealed Search + call setline(1, 'conceal this click here') + redraw + call assert_equal(['conceal click here '], ScreenLines(1, 20)) + + " click on 'h' of "here" puts cursor there + call Ntest_setmouse(1, 16) + call feedkeys("\", "tx") + call assert_equal([0, 1, 20, 0, 20], getcurpos()) + + bwipe! + set mouse& +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From b0dda500e9b45e39e872d76e8b753933c5467f83 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Aug 2023 14:59:25 +0800 Subject: vim-patch:9.0.1705: cursor position wrong when clicking on an unprintable char Problem: cursor position wrong when clicking on an unprintable char Solution: Don't update prev_ptr when wlv.n_extra is not zero. closes: vim/vim#12664 https://github.com/vim/vim/commit/b25dbb3f9b5885dd623af7a9fae890b8366b64e2 Tests only. Code superseded by patch 9.0.1725. --- test/old/testdir/test_normal.vim | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test') diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index c8e78dcf93..57b68bcbb6 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -4049,4 +4049,47 @@ func Test_normal_r_ctrl_v_cmd() bw! endfunc +" Test clicking on a TAB or an unprintable character in Normal mode +func Test_normal_click_on_ctrl_char() + let save_mouse = &mouse + set mouse=a + new + + call setline(1, "a\b\c") + redraw + call Ntest_setmouse(1, 1) + call feedkeys("\", 'xt') + call assert_equal([0, 1, 1, 0, 1], getcurpos()) + call Ntest_setmouse(1, 2) + call feedkeys("\", 'xt') + call assert_equal([0, 1, 2, 0, 8], getcurpos()) + call Ntest_setmouse(1, 3) + call feedkeys("\", 'xt') + call assert_equal([0, 1, 2, 0, 8], getcurpos()) + call Ntest_setmouse(1, 7) + call feedkeys("\", 'xt') + call assert_equal([0, 1, 2, 0, 8], getcurpos()) + call Ntest_setmouse(1, 8) + call feedkeys("\", 'xt') + call assert_equal([0, 1, 2, 0, 8], getcurpos()) + call Ntest_setmouse(1, 9) + call feedkeys("\", 'xt') + call assert_equal([0, 1, 3, 0, 9], getcurpos()) + call Ntest_setmouse(1, 10) + call feedkeys("\", 'xt') + call assert_equal([0, 1, 4, 0, 10], getcurpos()) + call Ntest_setmouse(1, 11) + call feedkeys("\", 'xt') + call assert_equal([0, 1, 4, 0, 10], getcurpos()) + call Ntest_setmouse(1, 12) + call feedkeys("\", 'xt') + call assert_equal([0, 1, 5, 0, 12], getcurpos()) + call Ntest_setmouse(1, 13) + call feedkeys("\", 'xt') + call assert_equal([0, 1, 5, 0, v:maxcol], getcurpos()) + + bwipe! + let &mouse = save_mouse +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit From 551998b7eed7dd411e4d14f65b108ae8a93c4081 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Aug 2023 15:00:03 +0800 Subject: vim-patch:9.0.1725: cursor pos wrong after concealed text with 'virtualedit' Problem: Wrong cursor position when clicking after concealed text with 'virtualedit'. Solution: Store virtual columns in ScreenCols[] instead of text columns, and always use coladvance() when clicking. This also fixes incorrect curswant when clicking on a TAB, so now Test_normal_click_on_ctrl_char() asserts the same results as the ones before patch 9.0.0048. closes: vim/vim#12808 https://github.com/vim/vim/commit/e500ae8e29ad921378085f5d70ee5c0c537be1ba Remove the mouse_adjust_click() function. There is a difference in behavior with the old mouse_adjust_click() approach: when clicking on the character immediately after concealed text that is completely hidden, cursor is put on the clicked character rather than at the start of the concealed text. The new behavior is better, but it causes unnecessary scrolling in a functional test (which is an existing issue unrelated to these patches), so adjust the test. Now fully merged: vim-patch:9.0.0177: cursor position wrong with 'virtualedit' and mouse click --- test/functional/ui/mouse_spec.lua | 3 +-- test/old/testdir/test_conceal.vim | 49 ++++++++++++++++++++++++++++++++++- test/old/testdir/test_normal.vim | 10 +++---- test/old/testdir/test_virtualedit.vim | 6 +++++ 4 files changed, 60 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index d126e27cde..657cc0c325 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -1089,7 +1089,6 @@ describe('ui/mouse/input', function() command([[setlocal concealcursor=ni nowrap shiftwidth=2 tabstop=4 list listchars=tab:>-]]) command([[syntax region X0 matchgroup=X1 start=/\*/ end=/\*/ concealends contains=X2]]) command([[syntax match X2 /cats/ conceal cchar=X contained]]) - -- No heap-use-after-free with multi-line syntax pattern #24317 command([[syntax match X3 /\n\@<=x/ conceal cchar=>]]) command([[highlight link X0 Normal]]) command([[highlight link X1 NonText]]) @@ -1497,7 +1496,6 @@ describe('ui/mouse/input', function() ]]) end) -- level 2 - wrapped - it('(level 3) click on non-wrapped lines', function() feed_command('let &conceallevel=3', 'echo') @@ -1535,6 +1533,7 @@ describe('ui/mouse/input', function() ]]) feed('<20,2>') + feed('zH') -- FIXME: unnecessary horizontal scrolling screen:expect([[ Section{0:>>--->--->---}t1 | {0:>--->--->---} t2 t3 t4 | diff --git a/test/old/testdir/test_conceal.vim b/test/old/testdir/test_conceal.vim index b9541b9e82..0ec171aa2f 100644 --- a/test/old/testdir/test_conceal.vim +++ b/test/old/testdir/test_conceal.vim @@ -349,9 +349,56 @@ func Test_conceal_mouse_click() call Ntest_setmouse(1, 16) call feedkeys("\", "tx") call assert_equal([0, 1, 20, 0, 20], getcurpos()) + " click on 'e' of "here" puts cursor there + call Ntest_setmouse(1, 19) + call feedkeys("\", "tx") + call assert_equal([0, 1, 23, 0, 23], getcurpos()) + " click after end of line puts cursor on 'e' without 'virtualedit' + call Ntest_setmouse(1, 20) + call feedkeys("\", "tx") + call assert_equal([0, 1, 23, 0, 24], getcurpos()) + call Ntest_setmouse(1, 21) + call feedkeys("\", "tx") + call assert_equal([0, 1, 23, 0, 25], getcurpos()) + call Ntest_setmouse(1, 22) + call feedkeys("\", "tx") + call assert_equal([0, 1, 23, 0, 26], getcurpos()) + call Ntest_setmouse(1, 31) + call feedkeys("\", "tx") + call assert_equal([0, 1, 23, 0, 35], getcurpos()) + call Ntest_setmouse(1, 32) + call feedkeys("\", "tx") + call assert_equal([0, 1, 23, 0, 36], getcurpos()) + + set virtualedit=all + redraw " Nvim: redraw_for_cursorcolumn() redraws for conceal + " click on 'h' of "here" puts cursor there + call Ntest_setmouse(1, 16) + call feedkeys("\", "tx") + call assert_equal([0, 1, 20, 0, 20], getcurpos()) + " click on 'e' of "here" puts cursor there + call Ntest_setmouse(1, 19) + call feedkeys("\", "tx") + call assert_equal([0, 1, 23, 0, 23], getcurpos()) + " click after end of line puts cursor there without 'virtualedit' + call Ntest_setmouse(1, 20) + call feedkeys("\", "tx") + call assert_equal([0, 1, 24, 0, 24], getcurpos()) + call Ntest_setmouse(1, 21) + call feedkeys("\", "tx") + call assert_equal([0, 1, 24, 1, 25], getcurpos()) + call Ntest_setmouse(1, 22) + call feedkeys("\", "tx") + call assert_equal([0, 1, 24, 2, 26], getcurpos()) + call Ntest_setmouse(1, 31) + call feedkeys("\", "tx") + call assert_equal([0, 1, 24, 11, 35], getcurpos()) + call Ntest_setmouse(1, 32) + call feedkeys("\", "tx") + call assert_equal([0, 1, 24, 12, 36], getcurpos()) bwipe! - set mouse& + set mouse& virtualedit& endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index 57b68bcbb6..c022133b4f 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -4062,13 +4062,13 @@ func Test_normal_click_on_ctrl_char() call assert_equal([0, 1, 1, 0, 1], getcurpos()) call Ntest_setmouse(1, 2) call feedkeys("\", 'xt') - call assert_equal([0, 1, 2, 0, 8], getcurpos()) + call assert_equal([0, 1, 2, 0, 2], getcurpos()) call Ntest_setmouse(1, 3) call feedkeys("\", 'xt') - call assert_equal([0, 1, 2, 0, 8], getcurpos()) + call assert_equal([0, 1, 2, 0, 3], getcurpos()) call Ntest_setmouse(1, 7) call feedkeys("\", 'xt') - call assert_equal([0, 1, 2, 0, 8], getcurpos()) + call assert_equal([0, 1, 2, 0, 7], getcurpos()) call Ntest_setmouse(1, 8) call feedkeys("\", 'xt') call assert_equal([0, 1, 2, 0, 8], getcurpos()) @@ -4080,13 +4080,13 @@ func Test_normal_click_on_ctrl_char() call assert_equal([0, 1, 4, 0, 10], getcurpos()) call Ntest_setmouse(1, 11) call feedkeys("\", 'xt') - call assert_equal([0, 1, 4, 0, 10], getcurpos()) + call assert_equal([0, 1, 4, 0, 11], getcurpos()) call Ntest_setmouse(1, 12) call feedkeys("\", 'xt') call assert_equal([0, 1, 5, 0, 12], getcurpos()) call Ntest_setmouse(1, 13) call feedkeys("\", 'xt') - call assert_equal([0, 1, 5, 0, v:maxcol], getcurpos()) + call assert_equal([0, 1, 5, 0, 13], getcurpos()) bwipe! let &mouse = save_mouse diff --git a/test/old/testdir/test_virtualedit.vim b/test/old/testdir/test_virtualedit.vim index a2baf276ac..f97b3f987d 100644 --- a/test/old/testdir/test_virtualedit.vim +++ b/test/old/testdir/test_virtualedit.vim @@ -586,6 +586,12 @@ func Test_virtualedit_mouse() call Ntest_setmouse(1, 9) call feedkeys("\", "xt") call assert_equal([0, 1, 6, 0, 9], getcurpos()) + call Ntest_setmouse(1, 12) + call feedkeys("\", "xt") + call assert_equal([0, 1, 9, 0, 12], getcurpos()) + call Ntest_setmouse(1, 13) + call feedkeys("\", "xt") + call assert_equal([0, 1, 10, 0, 13], getcurpos()) call Ntest_setmouse(1, 15) call feedkeys("\", "xt") call assert_equal([0, 1, 10, 2, 15], getcurpos()) -- cgit From 1d3d50e8f0e1c3438ad77a8727ad8d3f1333c79a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Aug 2023 19:31:15 +0800 Subject: test(ui/mouse_spec): mouse click with matchadd() concealed text --- test/functional/ui/mouse_spec.lua | 102 ++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 32 deletions(-) (limited to 'test') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index 657cc0c325..9c22d112d3 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -1073,38 +1073,7 @@ describe('ui/mouse/input', function() ]]) end) - describe('on concealed text', function() - -- Helpful for reading the test expectations: - -- :match Error /\^/ - - before_each(function() - screen:try_resize(25, 7) - screen:set_default_attr_ids({ - [0] = {bold=true, foreground=Screen.colors.Blue}, - c = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray }, - sm = {bold = true}, - }) - feed('ggdG') - - command([[setlocal concealcursor=ni nowrap shiftwidth=2 tabstop=4 list listchars=tab:>-]]) - command([[syntax region X0 matchgroup=X1 start=/\*/ end=/\*/ concealends contains=X2]]) - command([[syntax match X2 /cats/ conceal cchar=X contained]]) - command([[syntax match X3 /\n\@<=x/ conceal cchar=>]]) - command([[highlight link X0 Normal]]) - command([[highlight link X1 NonText]]) - command([[highlight link X2 NonText]]) - command([[highlight link X3 NonText]]) - - -- First column is there to retain the tabs. - insert([[ - |Section *t1* - | *t2* *t3* *t4* - |x 私は猫が大好き *cats* ✨🐈✨ - ]]) - - feed('ggGxgg') - end) - + local function test_mouse_click_conceal() it('(level 1) click on non-wrapped lines', function() feed_command('let &conceallevel=1', 'echo') @@ -1637,6 +1606,75 @@ describe('ui/mouse/input', function() ]]) end) -- level 3 - wrapped + end + + describe('on concealed text', function() + -- Helpful for reading the test expectations: + -- :match Error /\^/ + + before_each(function() + screen:try_resize(25, 7) + screen:set_default_attr_ids({ + [0] = { bold = true, foreground = Screen.colors.Blue }, + c = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray }, + sm = { bold = true }, + }) + feed('ggdG') + + command([[setlocal concealcursor=ni nowrap shiftwidth=2 tabstop=4 list listchars=tab:>-]]) + command([[highlight link X0 Normal]]) + command([[highlight link X1 NonText]]) + command([[highlight link X2 NonText]]) + command([[highlight link X3 NonText]]) + + -- First column is there to retain the tabs. + insert([[ + |Section *t1* + | *t2* *t3* *t4* + |x 私は猫が大好き *cats* ✨🐈✨ + ]]) + + feed('ggGxgg') + end) + + describe('(syntax)', function() + before_each(function() + command([[syntax region X0 matchgroup=X1 start=/\*/ end=/\*/ concealends contains=X2]]) + command([[syntax match X2 /cats/ conceal cchar=X contained]]) + command([[syntax match X3 /\n\@<=x/ conceal cchar=>]]) + end) + test_mouse_click_conceal() + end) + + describe('(matchadd())', function() + before_each(function() + funcs.matchadd('Conceal', [[\*]]) + funcs.matchadd('Conceal', [[cats]], 10, -1, { conceal = 'X' }) + funcs.matchadd('Conceal', [[\n\@<=x]], 10, -1, { conceal = '>' }) + end) + test_mouse_click_conceal() + end) + + -- FIXME: cannot make extmark conceal behave exactly like syntax conceal without cchar + pending('(extmarks)', function() + before_each(function() + local ns = meths.create_namespace('conceal') + meths.buf_set_extmark(0, ns, 0, 11, { end_col = 12, conceal = '' }) + meths.buf_set_extmark(0, ns, 0, 14, { end_col = 15, conceal = '' }) + meths.buf_set_extmark(0, ns, 1, 5, { end_col = 6, conceal = '' }) + meths.buf_set_extmark(0, ns, 1, 8, { end_col = 9, conceal = '' }) + meths.buf_set_extmark(0, ns, 1, 10, { end_col = 11, conceal = '' }) + meths.buf_set_extmark(0, ns, 1, 13, { end_col = 14, conceal = '' }) + meths.buf_set_extmark(0, ns, 1, 15, { end_col = 16, conceal = '' }) + meths.buf_set_extmark(0, ns, 1, 18, { end_col = 19, conceal = '' }) + meths.buf_set_extmark(0, ns, 2, 24, { end_col = 25, conceal = '' }) + meths.buf_set_extmark(0, ns, 2, 29, { end_col = 30, conceal = '' }) + meths.buf_set_extmark(0, ns, 2, 25, { end_col = 29, conceal = 'X' }) + meths.buf_set_extmark(0, ns, 2, 0, { end_col = 1, conceal = '>' }) + end) + test_mouse_click_conceal() + end) + end) it('getmousepos works correctly', function() -- cgit