diff options
Diffstat (limited to 'test/functional/ui/mouse_spec.lua')
-rw-r--r-- | test/functional/ui/mouse_spec.lua | 846 |
1 files changed, 406 insertions, 440 deletions
diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua index 1356ba3db8..0f30bf4471 100644 --- a/test/functional/ui/mouse_spec.lua +++ b/test/functional/ui/mouse_spec.lua @@ -1,8 +1,8 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local clear, feed, meths = helpers.clear, helpers.feed, helpers.meths +local clear, feed, api = helpers.clear, helpers.feed, helpers.api local insert, feed_command = helpers.insert, helpers.feed_command -local eq, funcs = helpers.eq, helpers.funcs +local eq, fn = helpers.eq, helpers.fn local poke_eventloop = helpers.poke_eventloop local command = helpers.command local exec = helpers.exec @@ -12,8 +12,8 @@ describe('ui/mouse/input', function() before_each(function() clear() - meths.set_option_value('mouse', 'a', {}) - meths.set_option_value('list', true, {}) + api.nvim_set_option_value('mouse', 'a', {}) + api.nvim_set_option_value('list', true, {}) -- NB: this is weird, but mostly irrelevant to the test -- So I didn't bother to change it command('set listchars=eol:$') @@ -21,21 +21,21 @@ describe('ui/mouse/input', function() screen = Screen.new(25, 5) screen:attach() screen:set_default_attr_ids({ - [0] = {bold=true, foreground=Screen.colors.Blue}, - [1] = {background = Screen.colors.LightGrey}, - [2] = {bold = true}, + [0] = { bold = true, foreground = Screen.colors.Blue }, + [1] = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, + [2] = { bold = true }, [3] = { foreground = Screen.colors.Blue, background = Screen.colors.LightGrey, bold = true, }, - [4] = {reverse = true}, - [5] = {bold = true, reverse = true}, - [6] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [7] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [8] = {foreground = Screen.colors.Brown}, + [4] = { reverse = true }, + [5] = { bold = true, reverse = true }, + [6] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [7] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [8] = { foreground = Screen.colors.Brown }, }) - command("set mousemodel=extend") + command('set mousemodel=extend') feed('itesting<cr>mouse<cr>support and selection<esc>') screen:expect([[ testing | @@ -48,13 +48,16 @@ describe('ui/mouse/input', function() it('single left click moves cursor', function() feed('<LeftMouse><2,1>') - screen:expect{grid=[[ + screen:expect { + grid = [[ testing | mo^use | support and selection | {0:~ }| | - ]], mouse_enabled=true} + ]], + mouse_enabled = true, + } feed('<LeftMouse><0,0>') screen:expect([[ ^testing | @@ -66,15 +69,18 @@ describe('ui/mouse/input', function() end) it("in external ui works with unset 'mouse'", function() - meths.set_option_value('mouse', '', {}) + api.nvim_set_option_value('mouse', '', {}) feed('<LeftMouse><2,1>') - screen:expect{grid=[[ + screen:expect { + grid = [[ testing | mo^use | support and selection | {0:~ }| | - ]], mouse_enabled=false} + ]], + mouse_enabled = false, + } feed('<LeftMouse><0,0>') screen:expect([[ ^testing | @@ -135,11 +141,11 @@ describe('ui/mouse/input', function() describe('tab drag', function() before_each(function() - screen:set_default_attr_ids( { - [0] = {bold=true, foreground=Screen.colors.Blue}, - tab = { background=Screen.colors.LightGrey, underline=true }, - sel = { bold=true }, - fill = { reverse=true } + screen:set_default_attr_ids({ + [0] = { bold = true, foreground = Screen.colors.Blue }, + tab = { background = Screen.colors.LightGrey, underline = true }, + sel = { bold = true }, + fill = { reverse = true }, }) end) @@ -151,24 +157,21 @@ describe('ui/mouse/input', function() screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftMouse><4,0>') screen:expect([[ {sel: + foo }{tab: + bar }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftDrag><14,0>') screen:expect([[ {tab: + bar }{sel: + foo }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) end) @@ -181,24 +184,27 @@ describe('ui/mouse/input', function() screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftMouse><11,0>') - screen:expect{grid=[[ + -- Prevent the case where screen:expect() with "unchanged" returns too early, + -- causing the click position to be overwritten by the next drag. + poke_eventloop() + screen:expect { + grid = [[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | - ]], unchanged=true} + ]], + unchanged = true, + } feed('<LeftDrag><6,0>') screen:expect([[ {sel: + bar }{tab: + foo }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) end) @@ -211,24 +217,21 @@ describe('ui/mouse/input', function() screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftMouse><4,0>') screen:expect([[ {sel: + foo }{tab: + bar }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftDrag><7,0>') screen:expect([[ {tab: + bar }{sel: + foo }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) end) @@ -241,32 +244,31 @@ describe('ui/mouse/input', function() screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftMouse><4,0>') screen:expect([[ {sel: + foo }{tab: + bar }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftDrag><4,1>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {sel: + foo }{tab: + bar }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | - ]], unchanged=true} + ]], + unchanged = true, + } feed('<LeftDrag><14,1>') screen:expect([[ {tab: + bar }{sel: + foo }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) end) @@ -279,32 +281,37 @@ describe('ui/mouse/input', function() screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftMouse><11,0>') - screen:expect{grid=[[ + -- Prevent the case where screen:expect() with "unchanged" returns too early, + -- causing the click position to be overwritten by the next drag. + poke_eventloop() + screen:expect { + grid = [[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | - ]], unchanged=true} + ]], + unchanged = true, + } feed('<LeftDrag><11,1>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | - ]], unchanged=true} + ]], + unchanged = true, + } feed('<LeftDrag><6,1>') screen:expect([[ {sel: + bar }{tab: + foo }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) end) @@ -317,32 +324,31 @@ describe('ui/mouse/input', function() screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftMouse><4,0>') screen:expect([[ {sel: + foo }{tab: + bar }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftDrag><4,1>') - screen:expect{grid=[[ + screen:expect { + grid = [[ {sel: + foo }{tab: + bar }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | - ]], unchanged=true} + ]], + unchanged = true, + } feed('<LeftDrag><7,1>') screen:expect([[ {tab: + bar }{sel: + foo }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) end) @@ -350,11 +356,11 @@ describe('ui/mouse/input', function() describe('tabline', function() before_each(function() - screen:set_default_attr_ids( { - [0] = {bold=true, foreground=Screen.colors.Blue}, - tab = { background=Screen.colors.LightGrey, underline=true }, - sel = { bold=true }, - fill = { reverse=true } + screen:set_default_attr_ids({ + [0] = { bold = true, foreground = Screen.colors.Blue }, + tab = { background = Screen.colors.LightGrey, underline = true }, + sel = { bold = true }, + fill = { reverse = true }, }) end) @@ -366,22 +372,20 @@ describe('ui/mouse/input', function() screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftMouse><4,0>') screen:expect([[ {sel: + foo }{tab: + bar }{fill: }{tab:X}| this is fo^o | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) end) it('left click in default tabline (position 24) closes tab', function() - meths.set_option_value('hidden', true, {}) + api.nvim_set_option_value('hidden', true, {}) feed_command('%delete') insert('this is foo') feed_command('silent file foo | tabnew | file bar') @@ -389,22 +393,19 @@ describe('ui/mouse/input', function() screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<LeftMouse><24,0>') screen:expect([[ this is fo^o | - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*3 | ]]) end) it('double click in default tabline (position 4) opens new tab', function() - meths.set_option_value('hidden', true, {}) + api.nvim_set_option_value('hidden', true, {}) feed_command('%delete') insert('this is foo') feed_command('silent file foo | tabnew | file bar') @@ -412,16 +413,14 @@ describe('ui/mouse/input', function() screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| this is ba^r{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<2-LeftMouse><4,0>') screen:expect([[ {sel: Name] }{tab: + foo + bar }{fill: }{tab:X}| {0:^$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) end) @@ -439,8 +438,8 @@ describe('ui/mouse/input', function() return call('Test', a:000 + [2]) endfunction ]]) - meths.set_option_value('tabline', '%@Test@test%X-%5@Test2@test2', {}) - meths.set_option_value('showtabline', 2, {}) + api.nvim_set_option_value('tabline', '%@Test@test%X-%5@Test2@test2', {}) + api.nvim_set_option_value('showtabline', 2, {}) screen:expect([[ {fill:test-test2 }| testing | @@ -448,59 +447,65 @@ describe('ui/mouse/input', function() support and selectio^n | | ]]) - meths.set_var('reply', {}) + api.nvim_set_var('reply', {}) end) local check_reply = function(expected) - eq(expected, meths.get_var('reply')) - meths.set_var('reply', {}) + eq(expected, api.nvim_get_var('reply')) + api.nvim_set_var('reply', {}) end - local test_click = function(name, click_str, click_num, mouse_button, - modifiers) - + local test_click = function(name, click_str, click_num, mouse_button, modifiers) local function doit(do_click) - eq(1, funcs.has('tablineat')) - do_click(0,3) - check_reply({0, click_num, mouse_button, modifiers}) - do_click(0,4) + eq(1, fn.has('tablineat')) + do_click(0, 3) + check_reply({ 0, click_num, mouse_button, modifiers }) + do_click(0, 4) check_reply({}) - do_click(0,6) - check_reply({5, click_num, mouse_button, modifiers, 2}) - do_click(0,13) - check_reply({5, click_num, mouse_button, modifiers, 2}) + do_click(0, 6) + check_reply({ 5, click_num, mouse_button, modifiers, 2 }) + do_click(0, 13) + check_reply({ 5, click_num, mouse_button, modifiers, 2 }) end it(name .. ' works (pseudokey)', function() - doit(function (row,col) - feed(click_str .. '<' .. col .. ',' .. row .. '>') + doit(function(row, col) + feed(click_str .. '<' .. col .. ',' .. row .. '>') end) end) it(name .. ' works (nvim_input_mouse)', function() - doit(function (row,col) - local buttons = {l='left',m='middle',r='right'} + doit(function(row, col) + local buttons = { l = 'left', m = 'middle', r = 'right' } local modstr = (click_num > 1) and tostring(click_num) or '' for char in string.gmatch(modifiers, '%w') do modstr = modstr .. char .. '-' -- - not needed but should be accepted end - meths.input_mouse(buttons[mouse_button], 'press', modstr, 0, row, col) + api.nvim_input_mouse(buttons[mouse_button], 'press', modstr, 0, row, col) end) end) end test_click('single left click', '<LeftMouse>', 1, 'l', ' ') test_click('shifted single left click', '<S-LeftMouse>', 1, 'l', 's ') - test_click('shifted single left click with alt modifier', - '<S-A-LeftMouse>', 1, 'l', 's a ') - test_click('shifted single left click with alt and ctrl modifiers', - '<S-C-A-LeftMouse>', 1, 'l', 'sca ') + test_click('shifted single left click with alt modifier', '<S-A-LeftMouse>', 1, 'l', 's a ') + test_click( + 'shifted single left click with alt and ctrl modifiers', + '<S-C-A-LeftMouse>', + 1, + 'l', + 'sca ' + ) -- <C-RightMouse> does not work - test_click('shifted single right click with alt modifier', - '<S-A-RightMouse>', 1, 'r', 's a ') + test_click('shifted single right click with alt modifier', '<S-A-RightMouse>', 1, 'r', 's a ') -- Modifiers do not work with MiddleMouse - test_click('shifted single middle click with alt and ctrl modifiers', - '<MiddleMouse>', 1, 'm', ' ') + test_click( + 'shifted single middle click with alt and ctrl modifiers', + '<MiddleMouse>', + 1, + 'm', + ' ' + ) -- Modifiers do not work with N-*Mouse test_click('double left click', '<2-LeftMouse>', 2, 'l', ' ') test_click('triple left click', '<3-LeftMouse>', 3, 'l', ' ') @@ -552,15 +557,15 @@ describe('ui/mouse/input', function() it('left drag changes visual selection after tab click', function() screen:set_default_attr_ids({ - [0] = {bold=true, foreground=Screen.colors.Blue}, - tab = { background=Screen.colors.LightGrey, underline=true }, - sel = { bold=true }, - fill = { reverse=true }, - vis = { background=Screen.colors.LightGrey } + [0] = { bold = true, foreground = Screen.colors.Blue }, + tab = { background = Screen.colors.LightGrey, underline = true }, + sel = { bold = true }, + fill = { reverse = true }, + vis = { background = Screen.colors.LightGrey, foreground = Screen.colors.Black }, }) feed_command('silent file foo | tabnew | file bar') insert('this is bar') - feed_command('tabprevious') -- go to first tab + feed_command('tabprevious') -- go to first tab screen:expect([[ {sel: + foo }{tab: + bar }{fill: }{tab:X}| testing | @@ -568,28 +573,26 @@ describe('ui/mouse/input', function() support and selectio^n | :tabprevious | ]]) - feed('<LeftMouse><10,0><LeftRelease>') -- go to second tab + feed('<LeftMouse><10,0><LeftRelease>') -- go to second tab helpers.poke_eventloop() feed('<LeftMouse><0,1>') screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| ^this is bar{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 :tabprevious | ]]) feed('<LeftDrag><4,1>') screen:expect([[ {tab: + foo }{sel: + bar }{fill: }{tab:X}| {vis:this}^ is bar{0:$} | - {0:~ }| - {0:~ }| + {0:~ }|*2 {sel:-- VISUAL --} | ]]) end) it('left drag changes visual selection in split layout', function() - screen:try_resize(53,14) + screen:try_resize(53, 14) command('set mouse=a') command('vsplit') command('wincmd l') @@ -597,58 +600,52 @@ describe('ui/mouse/input', function() command('enew') feed('ifoo\nbar<esc>') - screen:expect{grid=[[ + screen:expect { + grid = [[ testing │testing | mouse │mouse | support and selection │support and selection | - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| + {0:~ }│{0:~ }|*2 {0:~ }│{4:[No Name] [+] }| {0:~ }│foo{0:$} | {0:~ }│ba^r{0:$} | - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| + {0:~ }│{0:~ }|*4 {4:[No Name] [+] }{5:[No Name] [+] }| | - ]]} + ]], + } - meths.input_mouse('left', 'press', '', 0, 6, 27) - screen:expect{grid=[[ + api.nvim_input_mouse('left', 'press', '', 0, 6, 27) + screen:expect { + grid = [[ testing │testing | mouse │mouse | support and selection │support and selection | - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| + {0:~ }│{0:~ }|*2 {0:~ }│{4:[No Name] [+] }| {0:~ }│^foo{0:$} | {0:~ }│bar{0:$} | - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| + {0:~ }│{0:~ }|*4 {4:[No Name] [+] }{5:[No Name] [+] }| | - ]]} - meths.input_mouse('left', 'drag', '', 0, 7, 30) + ]], + } + api.nvim_input_mouse('left', 'drag', '', 0, 7, 30) - screen:expect{grid=[[ + screen:expect { + grid = [[ testing │testing | mouse │mouse | support and selection │support and selection | - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| + {0:~ }│{0:~ }|*2 {0:~ }│{4:[No Name] [+] }| {0:~ }│{1:foo}{3:$} | {0:~ }│{1:bar}{0:^$} | - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| - {0:~ }│{0:~ }| + {0:~ }│{0:~ }|*4 {4:[No Name] [+] }{5:[No Name] [+] }| {2:-- VISUAL --} | - ]]} + ]], + } end) it('two clicks will enter VISUAL and dragging selects words', function() @@ -788,7 +785,7 @@ describe('ui/mouse/input', function() end) it('ctrl + left click will search for a tag', function() - meths.set_option_value('tags', './non-existent-tags-file', {}) + api.nvim_set_option_value('tags', './non-existent-tags-file', {}) feed('<C-LeftMouse><0,0>') screen:expect([[ {6:E433: No tags file} | @@ -800,10 +797,29 @@ describe('ui/mouse/input', function() feed('<cr>') end) + it('x1 and x2 can be triggered by api', function() + api.nvim_set_var('x1_pressed', 0) + api.nvim_set_var('x1_released', 0) + api.nvim_set_var('x2_pressed', 0) + api.nvim_set_var('x2_released', 0) + command('nnoremap <X1Mouse> <Cmd>let g:x1_pressed += 1<CR>') + command('nnoremap <X1Release> <Cmd>let g:x1_released += 1<CR>') + command('nnoremap <X2Mouse> <Cmd>let g:x2_pressed += 1<CR>') + command('nnoremap <X2Release> <Cmd>let g:x2_released += 1<CR>') + api.nvim_input_mouse('x1', 'press', '', 0, 0, 0) + api.nvim_input_mouse('x1', 'release', '', 0, 0, 0) + api.nvim_input_mouse('x2', 'press', '', 0, 0, 0) + api.nvim_input_mouse('x2', 'release', '', 0, 0, 0) + eq(1, api.nvim_get_var('x1_pressed'), 'x1 pressed once') + eq(1, api.nvim_get_var('x1_released'), 'x1 released once') + eq(1, api.nvim_get_var('x2_pressed'), 'x2 pressed once') + eq(1, api.nvim_get_var('x2_released'), 'x2 released once') + end) + it('dragging vertical separator', function() screen:try_resize(45, 5) command('setlocal nowrap') - local oldwin = meths.get_current_win().id + local oldwin = api.nvim_get_current_win() command('rightbelow vnew') screen:expect([[ testing │{0:^$} | @@ -812,9 +828,9 @@ describe('ui/mouse/input', function() {4:[No Name] [+] }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'press', '', 0, 0, 22) + api.nvim_input_mouse('left', 'press', '', 0, 0, 22) poke_eventloop() - meths.input_mouse('left', 'drag', '', 0, 1, 12) + api.nvim_input_mouse('left', 'drag', '', 0, 1, 12) screen:expect([[ testing │{0:^$} | mouse │{0:~ }| @@ -822,7 +838,7 @@ describe('ui/mouse/input', function() {4:< Name] [+] }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'drag', '', 0, 2, 2) + api.nvim_input_mouse('left', 'drag', '', 0, 2, 2) screen:expect([[ te│{0:^$} | mo│{0:~ }| @@ -830,18 +846,17 @@ describe('ui/mouse/input', function() {4:< }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'release', '', 0, 2, 2) - meths.set_option_value('statuscolumn', 'foobar', { win = oldwin }) + api.nvim_input_mouse('left', 'release', '', 0, 2, 2) + api.nvim_set_option_value('statuscolumn', 'foobar', { win = oldwin }) screen:expect([[ {8:fo}│{0:^$} | - {8:fo}│{0:~ }| - {8:fo}│{0:~ }| + {8:fo}│{0:~ }|*2 {4:< }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'press', '', 0, 0, 2) + api.nvim_input_mouse('left', 'press', '', 0, 0, 2) poke_eventloop() - meths.input_mouse('left', 'drag', '', 0, 1, 12) + api.nvim_input_mouse('left', 'drag', '', 0, 1, 12) screen:expect([[ {8:foobar}testin│{0:^$} | {8:foobar}mouse │{0:~ }| @@ -849,7 +864,7 @@ describe('ui/mouse/input', function() {4:< Name] [+] }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'drag', '', 0, 2, 22) + api.nvim_input_mouse('left', 'drag', '', 0, 2, 22) screen:expect([[ {8:foobar}testing │{0:^$} | {8:foobar}mouse │{0:~ }| @@ -857,7 +872,7 @@ describe('ui/mouse/input', function() {4:[No Name] [+] }{5:[No Name] }| | ]]) - meths.input_mouse('left', 'release', '', 0, 2, 22) + api.nvim_input_mouse('left', 'release', '', 0, 2, 22) end) local function wheel(use_api) @@ -892,7 +907,7 @@ describe('ui/mouse/input', function() :vsp | ]]) if use_api then - meths.input_mouse('wheel', 'down', '', 0, 0, 0) + api.nvim_input_mouse('wheel', 'down', '', 0, 0, 0) else feed('<ScrollWheelDown><0,0>') end @@ -913,7 +928,7 @@ describe('ui/mouse/input', function() :vsp | ]]) if use_api then - meths.input_mouse('wheel', 'up', '', 0, 0, 27) + api.nvim_input_mouse('wheel', 'up', '', 0, 0, 27) else feed('<ScrollWheelUp><27,0>') end @@ -934,8 +949,8 @@ describe('ui/mouse/input', function() :vsp | ]]) if use_api then - meths.input_mouse('wheel', 'up', '', 0, 7, 27) - meths.input_mouse('wheel', 'up', '', 0, 7, 27) + api.nvim_input_mouse('wheel', 'up', '', 0, 7, 27) + api.nvim_input_mouse('wheel', 'up', '', 0, 7, 27) else feed('<ScrollWheelUp><27,7><ScrollWheelUp>') end @@ -967,27 +982,25 @@ describe('ui/mouse/input', function() it('horizontal scrolling (pseudokey)', function() command('set sidescroll=0') - feed("<esc>:set nowrap<cr>") + feed('<esc>:set nowrap<cr>') - feed("a <esc>20Ab<esc>") + feed('a <esc>20Ab<esc>') screen:expect([[ - | - | + |*2 bbbbbbbbbbbbbbb^b | {0:~ }| | ]]) - feed("<ScrollWheelLeft><0,0>") + feed('<ScrollWheelLeft><0,0>') screen:expect([[ - | - | + |*2 n bbbbbbbbbbbbbbbbbbb^b | {0:~ }| | ]]) - feed("^<ScrollWheelRight><0,0>") + feed('^<ScrollWheelRight><0,0>') screen:expect([[ g | | @@ -999,28 +1012,26 @@ describe('ui/mouse/input', function() it('horizontal scrolling (nvim_input_mouse)', function() command('set sidescroll=0') - feed("<esc>:set nowrap<cr>") + feed('<esc>:set nowrap<cr>') - feed("a <esc>20Ab<esc>") + feed('a <esc>20Ab<esc>') screen:expect([[ - | - | + |*2 bbbbbbbbbbbbbbb^b | {0:~ }| | ]]) - meths.input_mouse('wheel', 'left', '', 0, 0, 27) + api.nvim_input_mouse('wheel', 'left', '', 0, 0, 27) screen:expect([[ - | - | + |*2 n bbbbbbbbbbbbbbbbbbb^b | {0:~ }| | ]]) - feed("^") - meths.input_mouse('wheel', 'right', '', 0, 0, 0) + feed('^') + api.nvim_input_mouse('wheel', 'right', '', 0, 0, 0) screen:expect([[ g | | @@ -1034,7 +1045,7 @@ describe('ui/mouse/input', function() command('set nowrap') command('set sidescrolloff=4') - feed("I <esc>020ib<esc>0") + feed('I <esc>020ib<esc>0') screen:expect([[ testing | mouse | @@ -1043,7 +1054,7 @@ describe('ui/mouse/input', function() | ]]) - meths.input_mouse('wheel', 'right', '', 0, 0, 27) + api.nvim_input_mouse('wheel', 'right', '', 0, 0, 27) screen:expect([[ g | | @@ -1063,7 +1074,7 @@ describe('ui/mouse/input', function() | ]]) - meths.input_mouse('wheel', 'right', '', 0, 0, 27) + api.nvim_input_mouse('wheel', 'right', '', 0, 0, 27) screen:expect([[ g | | @@ -1083,8 +1094,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} {c: }t2{c: } {c: }t3{c: } {c: }| {c:>} 私は猫が大好き{0:>---}{c: X } {0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1094,8 +1104,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} {c: }t2{c: } {c: }t3{c: } {c: }| {c:>} 私は猫が大好き{0:>---}{c: X } {0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1105,8 +1114,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} {c: }t2{c: } {c: }t3{c: } {c: }| {c:>} 私は猫が大好き{0:>---}{c: X } {0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1116,8 +1124,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} {c: }t2{c: } {c: }t^3{c: } {c: }| {c:>} 私は猫が大好き{0:>---}{c: X } {0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1127,8 +1134,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} {c: }t2{c: } {c: }t3{c: } {c: }| {c:^>} 私は猫が大好き{0:>---}{c: X } {0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1138,8 +1144,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} {c: }t2{c: } {c: }t3{c: } {c: }| {c:>} 私は^猫が大好き{0:>---}{c: X } {0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1149,11 +1154,9 @@ describe('ui/mouse/input', function() {0:>--->--->---} {c: }t2{c: } {c: }t3{c: } {c: }| {c:>} 私は猫が大好き{0:>---}{c: ^X } {0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) - end) -- level 1 - non wrapped it('(level 1) click on wrapped lines', function() @@ -1166,8 +1169,7 @@ describe('ui/mouse/input', function() t4{c: } | {c:>} 私は猫が大好き{0:>---}{c: X} | {c: } ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><0,2>') @@ -1177,8 +1179,7 @@ describe('ui/mouse/input', function() ^t4{c: } | {c:>} 私は猫が大好き{0:>---}{c: X} | {c: } ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><8,3>') @@ -1188,8 +1189,7 @@ describe('ui/mouse/input', function() t4{c: } | {c:>} 私は猫^が大好き{0:>---}{c: X} | {c: } ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><21,3>') @@ -1199,8 +1199,7 @@ describe('ui/mouse/input', function() t4{c: } | {c:>} 私は猫が大好き{0:>---}{c: ^X} | {c: } ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><4,4>') @@ -1210,12 +1209,10 @@ describe('ui/mouse/input', function() t4{c: } | {c:>} 私は猫が大好き{0:>---}{c: X} | {c: } ✨^🐈✨ | - | - | + |*2 ]]) end) -- level 1 - wrapped - it('(level 2) click on non-wrapped lines', function() feed_command('let &conceallevel=2', 'echo') @@ -1225,8 +1222,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t3 t4 | {c:>} 私は猫が大好き{0:>---}{c:X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1236,8 +1232,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} ^t2 t3 t4 | {c:>} 私は猫が大好き{0:>---}{c:X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1247,19 +1242,17 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t^3 t4 | {c:>} 私は猫が大好き{0:>---}{c:X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) - feed('<esc><LeftMouse><0,2>') -- Weirdness + feed('<esc><LeftMouse><0,2>') -- Weirdness screen:expect([[ Section{0:>>--->--->---}t1 | {0:>--->--->---} t2 t3 t4 | {c:^>} 私は猫が大好き{0:>---}{c:X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1269,8 +1262,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t3 t4 | {c:>} 私は猫^が大好き{0:>---}{c:X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1280,8 +1272,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t3 t4 | {c:>} 私は猫が大好き{0:>---}{c:^X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) end) -- level 2 - non wrapped @@ -1295,8 +1286,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t3 t4 | {c:>} 私は猫が大好き{0:>---}{c:X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 {sm:-- INSERT --} | ]]) @@ -1306,8 +1296,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} ^t2 t3 t4 | {c:>} 私は猫が大好き{0:>---}{c:X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 {sm:-- INSERT --} | ]]) @@ -1317,19 +1306,17 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t^3 t4 | {c:>} 私は猫が大好き{0:>---}{c:X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 {sm:-- INSERT --} | ]]) - feed('<LeftMouse><0,2>') -- Weirdness + feed('<LeftMouse><0,2>') -- Weirdness screen:expect([[ Section{0:>>--->--->---}t1 | {0:>--->--->---} t2 t3 t4 | {c:^>} 私は猫が大好き{0:>---}{c:X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 {sm:-- INSERT --} | ]]) @@ -1339,8 +1326,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t3 t4 | {c:>} 私は猫^が大好き{0:>---}{c:X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 {sm:-- INSERT --} | ]]) @@ -1350,8 +1336,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t3 t4 | {c:>} 私は猫が大好き{0:>---}{c:^X} ✨{0:>}| | - {0:~ }| - {0:~ }| + {0:~ }|*2 {sm:-- INSERT --} | ]]) end) -- level 2 - non wrapped (insert mode) @@ -1366,8 +1351,7 @@ describe('ui/mouse/input', function() t4 | {c:>} 私は猫が大好き{0:>---}{c:X} | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><14,1>') @@ -1377,8 +1361,7 @@ describe('ui/mouse/input', function() t4 | {c:>} 私は猫が大好き{0:>---}{c:X} | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><18,1>') @@ -1388,8 +1371,7 @@ describe('ui/mouse/input', function() t4 | {c:>} 私は猫が大好き{0:>---}{c:X} | ✨🐈✨ | - | - | + |*2 ]]) -- NOTE: The click would ideally be on the 't' in 't4', but wrapping @@ -1405,8 +1387,7 @@ describe('ui/mouse/input', function() t4 | {c:>} 私は猫が大好き{0:>---}{c:X} | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><1,2>') @@ -1416,8 +1397,7 @@ describe('ui/mouse/input', function() t^4 | {c:>} 私は猫が大好き{0:>---}{c:X} | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><0,3>') @@ -1427,8 +1407,7 @@ describe('ui/mouse/input', function() t4 | {c:^>} 私は猫が大好き{0:>---}{c:X} | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><20,3>') @@ -1438,8 +1417,7 @@ describe('ui/mouse/input', function() t4 | {c:>} 私は猫が大好き{0:>---}{c:^X} | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><1,4>') @@ -1449,8 +1427,7 @@ describe('ui/mouse/input', function() t4 | {c:>} 私は猫が大好き{0:>---}{c:X} | ^✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><5,4>') @@ -1460,8 +1437,7 @@ describe('ui/mouse/input', function() t4 | {c:>} 私は猫が大好き{0:>---}{c:X} | ✨🐈^✨ | - | - | + |*2 ]]) end) -- level 2 - wrapped @@ -1474,8 +1450,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t3 t4 | ^ 私は猫が大好き{0:>----} ✨🐈| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1485,8 +1460,7 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t3 t4 | ^私は猫が大好き{0:>----} ✨🐈| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) @@ -1496,20 +1470,18 @@ describe('ui/mouse/input', function() {0:>--->--->---} t2 t3 t4 | 私は猫が大好^き{0:>----} ✨🐈| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) feed('<esc><LeftMouse><20,2>') - feed('zH') -- FIXME: unnecessary horizontal scrolling + feed('zH') -- FIXME: unnecessary horizontal scrolling screen:expect([[ Section{0:>>--->--->---}t1 | {0:>--->--->---} t2 t3 t4 | 私は猫が大好き{0:>----}^ ✨🐈| | - {0:~ }| - {0:~ }| + {0:~ }|*2 | ]]) end) -- level 3 - non wrapped @@ -1524,8 +1496,7 @@ describe('ui/mouse/input', function() t4 | 私は猫が大好き{0:>----} | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><18,1>') @@ -1535,8 +1506,7 @@ describe('ui/mouse/input', function() t4 | 私は猫が大好き{0:>----} | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><1,2>') @@ -1546,8 +1516,7 @@ describe('ui/mouse/input', function() t^4 | 私は猫が大好き{0:>----} | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><0,3>') @@ -1557,8 +1526,7 @@ describe('ui/mouse/input', function() t4 | ^ 私は猫が大好き{0:>----} | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><20,3>') @@ -1568,8 +1536,7 @@ describe('ui/mouse/input', function() t4 | 私は猫が大好き{0:>----}^ | ✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><1,4>') @@ -1579,8 +1546,7 @@ describe('ui/mouse/input', function() t4 | 私は猫が大好き{0:>----} | ^✨🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><3,4>') @@ -1590,8 +1556,7 @@ describe('ui/mouse/input', function() t4 | 私は猫が大好き{0:>----} | ✨^🐈✨ | - | - | + |*2 ]]) feed('<esc><LeftMouse><5,4>') @@ -1601,10 +1566,8 @@ describe('ui/mouse/input', function() t4 | 私は猫が大好き{0:>----} | ✨🐈^✨ | - | - | + |*2 ]]) - end) -- level 3 - wrapped end @@ -1648,66 +1611,65 @@ describe('ui/mouse/input', function() 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 = '>' }) + fn.matchadd('Conceal', [[\*]]) + fn.matchadd('Conceal', [[cats]], 10, -1, { conceal = 'X' }) + fn.matchadd('Conceal', [[\n\@<=x]], 10, -1, { conceal = '>' }) end) test_mouse_click_conceal() end) describe('(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 = '>' }) + local ns = api.nvim_create_namespace('conceal') + api.nvim_buf_set_extmark(0, ns, 0, 11, { end_col = 12, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 0, 14, { end_col = 15, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 5, { end_col = 6, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 8, { end_col = 9, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 10, { end_col = 11, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 13, { end_col = 14, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 15, { end_col = 16, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 1, 18, { end_col = 19, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 2, 24, { end_col = 25, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 2, 29, { end_col = 30, conceal = '' }) + api.nvim_buf_set_extmark(0, ns, 2, 25, { end_col = 29, conceal = 'X' }) + api.nvim_buf_set_extmark(0, ns, 2, 0, { end_col = 1, conceal = '>' }) end) test_mouse_click_conceal() end) - end) it('getmousepos() works correctly', function() - local winwidth = meths.get_option_value('winwidth', {}) + local winwidth = api.nvim_get_option_value('winwidth', {}) -- Set winwidth=1 so that window sizes don't change. - meths.set_option_value('winwidth', 1, {}) + api.nvim_set_option_value('winwidth', 1, {}) command('tabedit') - local tabpage = meths.get_current_tabpage() + local tabpage = api.nvim_get_current_tabpage() insert('hello') command('vsplit') local opts = { - relative='editor', - width=12, - height=1, - col=8, - row=1, - anchor='NW', - style='minimal', - border='single', - focusable=1 + relative = 'editor', + width = 12, + height = 1, + col = 8, + row = 1, + anchor = 'NW', + style = 'minimal', + border = 'single', + focusable = 1, } - local float = meths.open_win(meths.get_current_buf(), false, opts) + local float = api.nvim_open_win(api.nvim_get_current_buf(), false, opts) command('redraw') - local lines = meths.get_option_value('lines', {}) - local columns = meths.get_option_value('columns', {}) + local lines = api.nvim_get_option_value('lines', {}) + local columns = api.nvim_get_option_value('columns', {}) -- Test that screenrow and screencol are set properly for all positions. for row = 0, lines - 1 do for col = 0, columns - 1 do -- Skip the X button that would close the tab. if row ~= 0 or col ~= columns - 1 then - meths.input_mouse('left', 'press', '', 0, row, col) - meths.set_current_tabpage(tabpage) - local mousepos = funcs.getmousepos() + api.nvim_input_mouse('left', 'press', '', 0, row, col) + api.nvim_set_current_tabpage(tabpage) + local mousepos = fn.getmousepos() eq(row + 1, mousepos.screenrow) eq(col + 1, mousepos.screencol) -- All other values should be 0 when clicking on the command line. @@ -1730,20 +1692,24 @@ describe('ui/mouse/input', function() for win_col = 0, opts.width + 1 do local row = win_row + opts.row local col = win_col + opts.col - meths.input_mouse('left', 'press', '', 0, row, col) - local mousepos = funcs.getmousepos() - eq(float.id, mousepos.winid) + api.nvim_input_mouse('left', 'press', '', 0, row, col) + local mousepos = fn.getmousepos() + eq(float, mousepos.winid) eq(win_row + 1, mousepos.winrow) eq(win_col + 1, mousepos.wincol) local line = 0 local column = 0 local coladd = 0 - if win_row > 0 and win_row < opts.height + 1 - and win_col > 0 and win_col < opts.width + 1 then + if + win_row > 0 + and win_row < opts.height + 1 + and win_col > 0 + and win_col < opts.width + 1 + then -- Because of border, win_row and win_col don't need to be -- incremented by 1. - line = math.min(win_row, funcs.line('$')) - column = math.min(win_col, #funcs.getline(line) + 1) + line = math.min(win_row, fn.line('$')) + column = math.min(win_col, #fn.getline(line) + 1) coladd = win_col - column end eq(line, mousepos.line) @@ -1755,19 +1721,19 @@ describe('ui/mouse/input', function() -- Test that mouse position values are properly set for the floating -- window, after removing the border. opts.border = 'none' - meths.win_set_config(float, opts) + api.nvim_win_set_config(float, opts) command('redraw') for win_row = 0, opts.height - 1 do for win_col = 0, opts.width - 1 do local row = win_row + opts.row local col = win_col + opts.col - meths.input_mouse('left', 'press', '', 0, row, col) - local mousepos = funcs.getmousepos() - eq(float.id, mousepos.winid) + api.nvim_input_mouse('left', 'press', '', 0, row, col) + local mousepos = fn.getmousepos() + eq(float, mousepos.winid) eq(win_row + 1, mousepos.winrow) eq(win_col + 1, mousepos.wincol) - local line = math.min(win_row + 1, funcs.line('$')) - local column = math.min(win_col + 1, #funcs.getline(line) + 1) + local line = math.min(win_row + 1, fn.line('$')) + local column = math.min(win_col + 1, #fn.getline(line) + 1) local coladd = win_col + 1 - column eq(line, mousepos.line) eq(column, mousepos.column) @@ -1780,20 +1746,20 @@ describe('ui/mouse/input', function() -- that getmousepos() does not consider unfocusable floats. (see discussion -- in PR #14937 for details). opts.focusable = false - meths.win_set_config(float, opts) + api.nvim_win_set_config(float, opts) command('redraw') for nr = 1, 2 do - for win_row = 0, funcs.winheight(nr) - 1 do - for win_col = 0, funcs.winwidth(nr) - 1 do - local row = win_row + funcs.win_screenpos(nr)[1] - 1 - local col = win_col + funcs.win_screenpos(nr)[2] - 1 - meths.input_mouse('left', 'press', '', 0, row, col) - local mousepos = funcs.getmousepos() - eq(funcs.win_getid(nr), mousepos.winid) + for win_row = 0, fn.winheight(nr) - 1 do + for win_col = 0, fn.winwidth(nr) - 1 do + local row = win_row + fn.win_screenpos(nr)[1] - 1 + local col = win_col + fn.win_screenpos(nr)[2] - 1 + api.nvim_input_mouse('left', 'press', '', 0, row, col) + local mousepos = fn.getmousepos() + eq(fn.win_getid(nr), mousepos.winid) eq(win_row + 1, mousepos.winrow) eq(win_col + 1, mousepos.wincol) - local line = math.min(win_row + 1, funcs.line('$')) - local column = math.min(win_col + 1, #funcs.getline(line) + 1) + local line = math.min(win_row + 1, fn.line('$')) + local column = math.min(win_col + 1, #fn.getline(line) + 1) local coladd = win_col + 1 - column eq(line, mousepos.line) eq(column, mousepos.column) @@ -1804,34 +1770,34 @@ describe('ui/mouse/input', function() -- Restore state and release mouse. command('tabclose!') - meths.set_option_value('winwidth', winwidth, {}) - meths.input_mouse('left', 'release', '', 0, 0, 0) + api.nvim_set_option_value('winwidth', winwidth, {}) + api.nvim_input_mouse('left', 'release', '', 0, 0, 0) end) it('scroll keys are not translated into multiclicks and can be mapped #6211 #6989', function() - meths.set_var('mouse_up', 0) - meths.set_var('mouse_up2', 0) + api.nvim_set_var('mouse_up', 0) + api.nvim_set_var('mouse_up2', 0) command('nnoremap <ScrollWheelUp> <Cmd>let g:mouse_up += 1<CR>') command('nnoremap <2-ScrollWheelUp> <Cmd>let g:mouse_up2 += 1<CR>') feed('<ScrollWheelUp><0,0>') feed('<ScrollWheelUp><0,0>') - meths.input_mouse('wheel', 'up', '', 0, 0, 0) - meths.input_mouse('wheel', 'up', '', 0, 0, 0) - eq(4, meths.get_var('mouse_up')) - eq(0, meths.get_var('mouse_up2')) + api.nvim_input_mouse('wheel', 'up', '', 0, 0, 0) + api.nvim_input_mouse('wheel', 'up', '', 0, 0, 0) + eq(4, api.nvim_get_var('mouse_up')) + eq(0, api.nvim_get_var('mouse_up2')) end) it('<MouseMove> is not translated into multiclicks and can be mapped', function() - meths.set_var('mouse_move', 0) - meths.set_var('mouse_move2', 0) + api.nvim_set_var('mouse_move', 0) + api.nvim_set_var('mouse_move2', 0) command('nnoremap <MouseMove> <Cmd>let g:mouse_move += 1<CR>') command('nnoremap <2-MouseMove> <Cmd>let g:mouse_move2 += 1<CR>') feed('<MouseMove><0,0>') feed('<MouseMove><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')) + api.nvim_input_mouse('move', '', '', 0, 0, 0) + api.nvim_input_mouse('move', '', '', 0, 0, 0) + eq(4, api.nvim_get_var('mouse_move')) + eq(0, api.nvim_get_var('mouse_move2')) end) it('feeding <MouseMove> in Normal mode does not use uninitialized memory #19480', function() @@ -1858,127 +1824,127 @@ describe('ui/mouse/input', function() vmenu PopUp.baz y:<C-U>let g:menustr = 'baz'<CR> ]]) - meths.win_set_cursor(0, {1, 0}) - meths.input_mouse('right', 'press', '', 0, 0, 4) - meths.input_mouse('right', 'release', '', 0, 0, 4) + api.nvim_win_set_cursor(0, { 1, 0 }) + api.nvim_input_mouse('right', 'press', '', 0, 0, 4) + api.nvim_input_mouse('right', 'release', '', 0, 0, 4) feed('<Down><Down><CR>') - eq('bar', meths.get_var('menustr')) - eq({1, 4}, meths.win_get_cursor(0)) + eq('bar', api.nvim_get_var('menustr')) + eq({ 1, 4 }, api.nvim_win_get_cursor(0)) -- Test for right click in visual mode inside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, {1, 9}) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 9 }) feed('vee') - meths.input_mouse('right', 'press', '', 0, 0, 11) - meths.input_mouse('right', 'release', '', 0, 0, 11) + api.nvim_input_mouse('right', 'press', '', 0, 0, 11) + api.nvim_input_mouse('right', 'release', '', 0, 0, 11) feed('<Down><CR>') - eq({1, 9}, meths.win_get_cursor(0)) - eq('ran away', funcs.getreg('"')) + eq({ 1, 9 }, api.nvim_win_get_cursor(0)) + eq('ran away', fn.getreg('"')) -- Test for right click in visual mode right before the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, {1, 9}) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 9 }) feed('vee') - meths.input_mouse('right', 'press', '', 0, 0, 8) - meths.input_mouse('right', 'release', '', 0, 0, 8) + api.nvim_input_mouse('right', 'press', '', 0, 0, 8) + api.nvim_input_mouse('right', 'release', '', 0, 0, 8) feed('<Down><CR>') - eq({1, 8}, meths.win_get_cursor(0)) - eq('', funcs.getreg('"')) + eq({ 1, 8 }, api.nvim_win_get_cursor(0)) + eq('', fn.getreg('"')) -- Test for right click in visual mode right after the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, {1, 9}) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 9 }) feed('vee') - meths.input_mouse('right', 'press', '', 0, 0, 17) - meths.input_mouse('right', 'release', '', 0, 0, 17) + api.nvim_input_mouse('right', 'press', '', 0, 0, 17) + api.nvim_input_mouse('right', 'release', '', 0, 0, 17) feed('<Down><CR>') - eq({1, 17}, meths.win_get_cursor(0)) - eq('', funcs.getreg('"')) + eq({ 1, 17 }, api.nvim_win_get_cursor(0)) + eq('', fn.getreg('"')) -- Test for right click in block-wise visual mode inside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, {1, 15}) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 15 }) feed('<C-V>j3l') - meths.input_mouse('right', 'press', '', 0, 1, 16) - meths.input_mouse('right', 'release', '', 0, 1, 16) + api.nvim_input_mouse('right', 'press', '', 0, 1, 16) + api.nvim_input_mouse('right', 'release', '', 0, 1, 16) feed('<Down><CR>') - eq({1, 15}, meths.win_get_cursor(0)) - eq('\0224', funcs.getregtype('"')) + eq({ 1, 15 }, api.nvim_win_get_cursor(0)) + eq('\0224', fn.getregtype('"')) -- Test for right click in block-wise visual mode outside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, {1, 15}) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 15 }) feed('<C-V>j3l') - meths.input_mouse('right', 'press', '', 0, 1, 1) - meths.input_mouse('right', 'release', '', 0, 1, 1) + api.nvim_input_mouse('right', 'press', '', 0, 1, 1) + api.nvim_input_mouse('right', 'release', '', 0, 1, 1) feed('<Down><CR>') - eq({2, 1}, meths.win_get_cursor(0)) - eq('v', funcs.getregtype('"')) - eq('', funcs.getreg('"')) + eq({ 2, 1 }, api.nvim_win_get_cursor(0)) + eq('v', fn.getregtype('"')) + eq('', fn.getreg('"')) -- Test for right click in line-wise visual mode inside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, {1, 15}) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 15 }) feed('V') - meths.input_mouse('right', 'press', '', 0, 0, 9) - meths.input_mouse('right', 'release', '', 0, 0, 9) + api.nvim_input_mouse('right', 'press', '', 0, 0, 9) + api.nvim_input_mouse('right', 'release', '', 0, 0, 9) feed('<Down><CR>') - 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)) + eq({ 1, 0 }, api.nvim_win_get_cursor(0)) -- After yanking, the cursor goes to 1,1 + eq('V', fn.getregtype('"')) + eq(1, #fn.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}) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 15 }) feed('Vj') - meths.input_mouse('right', 'press', '', 0, 1, 19) - meths.input_mouse('right', 'release', '', 0, 1, 19) + api.nvim_input_mouse('right', 'press', '', 0, 1, 19) + api.nvim_input_mouse('right', 'release', '', 0, 1, 19) feed('<Down><CR>') - 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)) + eq({ 1, 0 }, api.nvim_win_get_cursor(0)) -- After yanking, the cursor goes to 1,1 + eq('V', fn.getregtype('"')) + eq(2, #fn.getreg('"', 1, true)) -- Test for right click in line-wise visual mode outside the selection - funcs.setreg('"', '') - meths.win_set_cursor(0, {1, 15}) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 15 }) feed('V') - meths.input_mouse('right', 'press', '', 0, 1, 9) - meths.input_mouse('right', 'release', '', 0, 1, 9) + api.nvim_input_mouse('right', 'press', '', 0, 1, 9) + api.nvim_input_mouse('right', 'release', '', 0, 1, 9) feed('<Down><CR>') - eq({2, 9}, meths.win_get_cursor(0)) - eq('', funcs.getreg('"')) + eq({ 2, 9 }, api.nvim_win_get_cursor(0)) + eq('', fn.getreg('"')) -- Try clicking outside the window - funcs.setreg('"', '') - meths.win_set_cursor(0, {2, 1}) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 2, 1 }) feed('vee') - meths.input_mouse('right', 'press', '', 0, 6, 1) - meths.input_mouse('right', 'release', '', 0, 6, 1) + api.nvim_input_mouse('right', 'press', '', 0, 6, 1) + api.nvim_input_mouse('right', 'release', '', 0, 6, 1) feed('<Down><CR>') - eq(2, funcs.winnr()) - eq('', funcs.getreg('"')) + eq(2, fn.winnr()) + eq('', fn.getreg('"')) -- Test for right click in visual mode inside the selection with vertical splits command('wincmd t') command('rightbelow vsplit') - funcs.setreg('"', '') - meths.win_set_cursor(0, {1, 9}) + fn.setreg('"', '') + api.nvim_win_set_cursor(0, { 1, 9 }) feed('vee') - meths.input_mouse('right', 'press', '', 0, 0, 52) - meths.input_mouse('right', 'release', '', 0, 0, 52) + api.nvim_input_mouse('right', 'press', '', 0, 0, 52) + api.nvim_input_mouse('right', 'release', '', 0, 0, 52) feed('<Down><CR>') - eq({1, 9}, meths.win_get_cursor(0)) - eq('ran away', funcs.getreg('"')) + eq({ 1, 9 }, api.nvim_win_get_cursor(0)) + eq('ran away', fn.getreg('"')) -- Test for right click inside visual selection at bottom of window with winbar command('setlocal winbar=WINBAR') feed('2yyP') - funcs.setreg('"', '') + fn.setreg('"', '') feed('G$vbb') - meths.input_mouse('right', 'press', '', 0, 4, 61) - meths.input_mouse('right', 'release', '', 0, 4, 61) + api.nvim_input_mouse('right', 'press', '', 0, 4, 61) + api.nvim_input_mouse('right', 'release', '', 0, 4, 61) feed('<Down><CR>') - eq({4, 20}, meths.win_get_cursor(0)) - eq('the moon', funcs.getreg('"')) + eq({ 4, 20 }, api.nvim_win_get_cursor(0)) + eq('the moon', fn.getreg('"')) end) end) |