From ceb09701f29dcabcf219f458fffbb64f5adced9b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 24 Jul 2022 13:58:29 +0800 Subject: feat(api): add "move" to nvim_input_mouse --- test/functional/ui/mouse_spec.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'test/functional/ui/mouse_spec.lua') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index 9896b11218..8c5475ecce 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -1585,7 +1585,20 @@ describe('ui/mouse/input', function() eq(0, meths.get_var('mouse_up2')) end) - it('feeding does not use uninitialized memory #19480', function() + it(' is not translated into multiclicks and can be mapped', function() + meths.set_var('mouse_move', 0) + meths.set_var('mouse_move2', 0) + command('nnoremap let g:mouse_move += 1') + command('nnoremap <2-MouseMove> let g:mouse_move2 += 1') + feed('<0,0>') + feed('<0,0>') + meths.input_mouse('move', '', '', 0, 0, 0) + meths.input_mouse('move', '', '', 0, 0, 0) + eq(4, meths.get_var('mouse_move')) + eq(0, meths.get_var('mouse_move2')) + end) + + it('feeding in Normal mode does not use uninitialized memory #19480', function() feed('') helpers.poke_eventloop() helpers.assert_alive() -- cgit From 8317b9199edc6936fec829f4908f9c74dc874ce4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 24 Sep 2022 22:28:41 +0800 Subject: fix(input): use click number of last click for mouse drag (#20300) --- test/functional/ui/mouse_spec.lua | 96 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 6 deletions(-) (limited to 'test/functional/ui/mouse_spec.lua') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index 8c5475ecce..cb8dfdb8e1 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -648,8 +648,10 @@ describe('ui/mouse/input', function() ]]} end) - it('two clicks will select the word and enter VISUAL', function() - feed('<2,2><2,2>') + it('two clicks will enter VISUAL and dragging selects words', function() + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') screen:expect([[ testing | mouse | @@ -657,10 +659,38 @@ describe('ui/mouse/input', function() {0:~ }| {2:-- VISUAL --} | ]]) + feed('<0,1>') + screen:expect([[ + testing | + ^m{1:ouse} | + {1:support} and selection | + {0:~ }| + {2:-- VISUAL --} | + ]]) + feed('<4,0>') + screen:expect([[ + ^t{1:esting} | + {1:mouse} | + {1:support} and selection | + {0:~ }| + {2:-- VISUAL --} | + ]]) + feed('<14,2>') + screen:expect([[ + testing | + mouse | + {1:support and selectio}^n | + {0:~ }| + {2:-- VISUAL --} | + ]]) end) - it('three clicks will select the line and enter VISUAL LINE', function() - feed('<2,2><2,2><2,2>') + it('three clicks will enter VISUAL LINE and dragging selects lines', function() + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') screen:expect([[ testing | mouse | @@ -668,10 +698,40 @@ describe('ui/mouse/input', function() {0:~ }| {2:-- VISUAL LINE --} | ]]) + feed('<0,1>') + screen:expect([[ + testing | + ^m{1:ouse} | + {1:support and selection} | + {0:~ }| + {2:-- VISUAL LINE --} | + ]]) + feed('<4,0>') + screen:expect([[ + {1:test}^i{1:ng} | + {1:mouse} | + {1:support and selection} | + {0:~ }| + {2:-- VISUAL LINE --} | + ]]) + feed('<14,2>') + screen:expect([[ + testing | + mouse | + {1:support and se}^l{1:ection} | + {0:~ }| + {2:-- VISUAL LINE --} | + ]]) end) - it('four clicks will enter VISUAL BLOCK', function() - feed('<2,2><2,2><2,2><2,2>') + it('four clicks will enter VISUAL BLOCK and dragging selects blockwise', function() + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') + feed('<2,2>') screen:expect([[ testing | mouse | @@ -679,6 +739,30 @@ describe('ui/mouse/input', function() {0:~ }| {2:-- VISUAL BLOCK --} | ]]) + feed('<0,1>') + screen:expect([[ + testing | + ^m{1:ou}se | + {1:sup}port and selection | + {0:~ }| + {2:-- VISUAL BLOCK --} | + ]]) + feed('<4,0>') + screen:expect([[ + te{1:st}^ing | + mo{1:use} | + su{1:ppo}rt and selection | + {0:~ }| + {2:-- VISUAL BLOCK --} | + ]]) + feed('<14,2>') + screen:expect([[ + testing | + mouse | + su{1:pport and se}^lection | + {0:~ }| + {2:-- VISUAL BLOCK --} | + ]]) end) it('right click extends visual selection to the clicked location', function() -- cgit From 96cf385a7f4ab29f6987c10b5c3625d99b22f6fc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 19 Oct 2022 11:32:26 +0800 Subject: vim-patch:9.0.0739: mouse column not correctly used for popup_setpos (#20729) Problem: Mouse column not correctly used for popup_setpos. Solution: Adjust off-by-one error and handle Visual line selection properly. (Yee Cheng Chin, closes vim/vim#11356) https://github.com/vim/vim/commit/17822c507c03d509037c9ee5eee5cfbb201b3f01 The test_termcodes.vim test cannot be used. Use a Lua test instead. --- test/functional/ui/mouse_spec.lua | 130 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) (limited to 'test/functional/ui/mouse_spec.lua') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index cb8dfdb8e1..b3ea0edb12 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -4,6 +4,7 @@ local clear, feed, meths = helpers.clear, helpers.feed, helpers.meths local insert, feed_command = helpers.insert, helpers.feed_command local eq, funcs = helpers.eq, helpers.funcs local command = helpers.command +local exec = helpers.exec describe('ui/mouse/input', function() local screen @@ -1687,4 +1688,133 @@ describe('ui/mouse/input', function() helpers.poke_eventloop() helpers.assert_alive() end) + + it('mousemodel=popup_setpos', function() + screen:try_resize(80, 24) + exec([[ + 5new + call setline(1, ['the dish ran away with the spoon', + \ 'the cow jumped over the moon' ]) + + set mouse=a mousemodel=popup_setpos + + aunmenu PopUp + nmenu PopUp.foo :let g:menustr = 'foo' + nmenu PopUp.bar :let g:menustr = 'bar' + nmenu PopUp.baz :let g:menustr = 'baz' + vmenu PopUp.foo y:let g:menustr = 'foo' + vmenu PopUp.bar y:let g:menustr = 'bar' + vmenu PopUp.baz y:let g:menustr = 'baz' + ]]) + + meths.win_set_cursor(0, {1, 0}) + meths.input_mouse('right', 'press', '', 0, 0, 4) + meths.input_mouse('right', 'release', '', 0, 0, 4) + feed('') + eq('bar', meths.get_var('menustr')) + eq({1, 4}, meths.win_get_cursor(0)) + + -- Test for right click in visual mode inside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 9}) + feed('vee') + meths.input_mouse('right', 'press', '', 0, 0, 11) + meths.input_mouse('right', 'release', '', 0, 0, 11) + feed('') + eq({1, 9}, meths.win_get_cursor(0)) + eq('ran away', funcs.getreg('"')) + + -- Test for right click in visual mode right before the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 9}) + feed('vee') + meths.input_mouse('right', 'press', '', 0, 0, 8) + meths.input_mouse('right', 'release', '', 0, 0, 8) + feed('') + eq({1, 8}, meths.win_get_cursor(0)) + eq('', funcs.getreg('"')) + + -- Test for right click in visual mode right after the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 9}) + feed('vee') + meths.input_mouse('right', 'press', '', 0, 0, 17) + meths.input_mouse('right', 'release', '', 0, 0, 17) + feed('') + eq({1, 17}, meths.win_get_cursor(0)) + eq('', funcs.getreg('"')) + + -- Test for right click in block-wise visual mode inside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 15}) + feed('j3l') + meths.input_mouse('right', 'press', '', 0, 1, 16) + meths.input_mouse('right', 'release', '', 0, 1, 16) + feed('') + eq({1, 15}, meths.win_get_cursor(0)) + eq('\0224', funcs.getregtype('"')) + + -- Test for right click in block-wise visual mode outside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 15}) + feed('j3l') + meths.input_mouse('right', 'press', '', 0, 1, 1) + meths.input_mouse('right', 'release', '', 0, 1, 1) + feed('') + eq({2, 1}, meths.win_get_cursor(0)) + eq('v', funcs.getregtype('"')) + eq('', funcs.getreg('"')) + + -- Test for right click in line-wise visual mode inside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 15}) + feed('V') + meths.input_mouse('right', 'press', '', 0, 0, 9) + meths.input_mouse('right', 'release', '', 0, 0, 9) + feed('') + eq({1, 0}, meths.win_get_cursor(0)) -- After yanking, the cursor goes to 1,1 + eq('V', funcs.getregtype('"')) + eq(1, #funcs.getreg('"', 1, true)) + + -- Test for right click in multi-line line-wise visual mode inside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 15}) + feed('Vj') + meths.input_mouse('right', 'press', '', 0, 1, 19) + meths.input_mouse('right', 'release', '', 0, 1, 19) + feed('') + eq({1, 0}, meths.win_get_cursor(0)) -- After yanking, the cursor goes to 1,1 + eq('V', funcs.getregtype('"')) + eq(2, #funcs.getreg('"', 1, true)) + + -- Test for right click in line-wise visual mode outside the selection + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 15}) + feed('V') + meths.input_mouse('right', 'press', '', 0, 1, 9) + meths.input_mouse('right', 'release', '', 0, 1, 9) + feed('') + eq({2, 9}, meths.win_get_cursor(0)) + eq('', funcs.getreg('"')) + + -- Try clicking on the status line + funcs.setreg('"', '') + meths.win_set_cursor(0, {1, 9}) + feed('vee') + meths.input_mouse('right', 'press', '', 0, 5, 1) + meths.input_mouse('right', 'release', '', 0, 5, 1) + feed('') + eq({1, 9}, meths.win_get_cursor(0)) + eq('ran away', funcs.getreg('"')) + + -- Try clicking outside the window + funcs.setreg('"', '') + meths.win_set_cursor(0, {2, 1}) + feed('vee') + meths.input_mouse('right', 'press', '', 0, 6, 1) + meths.input_mouse('right', 'release', '', 0, 6, 1) + feed('') + eq(2, funcs.winnr()) + eq('', funcs.getreg('"')) + end) end) -- cgit From f1b88ced07a5dcc62cd847cade2ed97e23fffbf9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 23 Nov 2022 12:14:16 +0800 Subject: fix(options): fix local 'sidescrolloff' doesn't work for mouse (#21162) Missing part of Vim patch 8.1.0864. --- test/functional/ui/mouse_spec.lua | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test/functional/ui/mouse_spec.lua') diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index b3ea0edb12..f705678bd5 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -968,6 +968,49 @@ describe('ui/mouse/input', function() ]]) end) + it("'sidescrolloff' applies to horizontal scrolling", function() + command('set nowrap') + command('set sidescrolloff=4') + + feed("I 020ib0") + screen:expect([[ + testing | + mouse | + ^bbbbbbbbbbbbbbbbbbbb supp| + {0:~ }| + | + ]]) + + meths.input_mouse('wheel', 'right', '', 0, 0, 27) + screen:expect([[ + g | + | + bbbb^bbbbbbbbbb support an| + {0:~ }| + | + ]]) + + -- window-local 'sidescrolloff' should override global value. #21162 + command('setlocal sidescrolloff=2') + feed('0') + screen:expect([[ + testing | + mouse | + ^bbbbbbbbbbbbbbbbbbbb supp| + {0:~ }| + | + ]]) + + meths.input_mouse('wheel', 'right', '', 0, 0, 27) + screen:expect([[ + g | + | + bb^bbbbbbbbbbbb support an| + {0:~ }| + | + ]]) + end) + describe('on concealed text', function() -- Helpful for reading the test expectations: -- :match Error /\^/ -- cgit