aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-24 15:24:15 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-09-04 21:18:23 +0800
commit82d128405aaeb619a0c04353449f5717da126249 (patch)
treeb5e4773025a714f20391e800232ec35929794133
parentceb09701f29dcabcf219f458fffbb64f5adced9b (diff)
downloadrneovim-82d128405aaeb619a0c04353449f5717da126249.tar.gz
rneovim-82d128405aaeb619a0c04353449f5717da126249.tar.bz2
rneovim-82d128405aaeb619a0c04353449f5717da126249.zip
feat(pum): pretend 'mousemoveevent' is set when showing right-click menu
-rw-r--r--src/nvim/popupmenu.c7
-rw-r--r--test/functional/terminal/tui_spec.lua52
-rw-r--r--test/functional/ui/popupmenu_spec.lua8
3 files changed, 67 insertions, 0 deletions
diff --git a/src/nvim/popupmenu.c b/src/nvim/popupmenu.c
index 0d9080ceb7..2265334a45 100644
--- a/src/nvim/popupmenu.c
+++ b/src/nvim/popupmenu.c
@@ -1042,6 +1042,10 @@ void pum_show_popupmenu(vimmenu_T *menu)
pum_scrollbar = 0;
pum_height = pum_size;
pum_position_at_mouse(20);
+ if (!p_mousemev) {
+ // Pretend 'mousemoveevent' is set.
+ ui_call_option_set(STATIC_CSTR_AS_STRING("mousemoveevent"), BOOLEAN_OBJ(true));
+ }
pum_selected = -1;
pum_first = 0;
@@ -1102,6 +1106,9 @@ void pum_show_popupmenu(vimmenu_T *menu)
xfree(array);
pum_undisplay(true);
+ if (!p_mousemev) {
+ ui_call_option_set(STATIC_CSTR_AS_STRING("mousemoveevent"), BOOLEAN_OBJ(false));
+ }
}
void pum_make_popup(const char *path_name, int use_mouse_pos)
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index 4f444316c3..3c56ad5f79 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -21,6 +21,7 @@ local nvim_set = helpers.nvim_set
local ok = helpers.ok
local read_file = helpers.read_file
local funcs = helpers.funcs
+local meths = helpers.meths
if helpers.pending_win32(pending) then return end
@@ -666,6 +667,57 @@ describe('TUI', function()
]], attrs)
end)
+ it('mouse events work with right-click menu', function()
+ child_session:request('nvim_command', [[
+ call setline(1, 'popup menu test')
+ set mouse=a mousemodel=popup
+
+ aunmenu PopUp
+ menu PopUp.foo :let g:menustr = 'foo'<CR>
+ menu PopUp.bar :let g:menustr = 'bar'<CR>
+ menu PopUp.baz :let g:menustr = 'baz'<CR>
+ highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse
+ highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold
+ ]])
+ local attrs = screen:get_default_attr_ids()
+ attrs[11] = {underline = true, reverse = true}
+ attrs[12] = {underline = true, reverse = true, bold = true}
+ meths.input_mouse('right', 'press', '', 0, 0, 4)
+ screen:expect([[
+ {1:p}opup menu test |
+ {4:~ }{11: foo }{4: }|
+ {4:~ }{11: bar }{4: }|
+ {4:~ }{11: baz }{4: }|
+ {5:[No Name] [+] }|
+ |
+ {3:-- TERMINAL --} |
+ ]], attrs)
+ meths.input_mouse('right', 'release', '', 0, 0, 4)
+ screen:expect_unchanged()
+ meths.input_mouse('move', '', '', 0, 3, 6)
+ screen:expect([[
+ {1:p}opup menu test |
+ {4:~ }{11: foo }{4: }|
+ {4:~ }{11: bar }{4: }|
+ {4:~ }{12: baz }{4: }|
+ {5:[No Name] [+] }|
+ |
+ {3:-- TERMINAL --} |
+ ]], attrs)
+ meths.input_mouse('left', 'press', '', 0, 2, 6)
+ screen:expect([[
+ {1:p}opup menu test |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] [+] }|
+ :let g:menustr = 'bar' |
+ {3:-- TERMINAL --} |
+ ]], attrs)
+ meths.input_mouse('left', 'release', '', 0, 2, 6)
+ screen:expect_unchanged()
+ end)
+
it('paste: Insert mode', function()
-- "bracketed paste"
feed_data('i""\027i\027[200~')
diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua
index b16e404ea8..3c752875f0 100644
--- a/test/functional/ui/popupmenu_spec.lua
+++ b/test/functional/ui/popupmenu_spec.lua
@@ -2839,6 +2839,7 @@ describe('builtin popupmenu', function()
:let g:menustr = 'foo' |
]])
eq('foo', meths.get_var('menustr'))
+ eq(false, screen.options.mousemoveevent)
feed('<RightMouse><4,0>')
screen:expect([[
^popup menu test |
@@ -2848,6 +2849,7 @@ describe('builtin popupmenu', function()
{1:~ }|
:let g:menustr = 'foo' |
]])
+ eq(true, screen.options.mousemoveevent)
feed('<MouseMove><6,3>')
screen:expect([[
^popup menu test |
@@ -2857,6 +2859,7 @@ describe('builtin popupmenu', function()
{1:~ }|
:let g:menustr = 'foo' |
]])
+ eq(true, screen.options.mousemoveevent)
feed('<LeftMouse><6,2>')
screen:expect([[
^popup menu test |
@@ -2866,6 +2869,7 @@ describe('builtin popupmenu', function()
{1:~ }|
:let g:menustr = 'bar' |
]])
+ eq(false, screen.options.mousemoveevent)
eq('bar', meths.get_var('menustr'))
end)
end)
@@ -3075,6 +3079,7 @@ describe('builtin popupmenu with ui/ext_multigrid', function()
:let g:menustr = 'foo' |
]]})
eq('foo', meths.get_var('menustr'))
+ eq(false, screen.options.mousemoveevent)
meths.input_mouse('right', 'press', '', 2, 0, 4)
screen:expect({grid=[[
## grid 1
@@ -3097,6 +3102,7 @@ describe('builtin popupmenu with ui/ext_multigrid', function()
{n: bar }|
{n: baz }|
]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 100}}})
+ eq(true, screen.options.mousemoveevent)
meths.input_mouse('move', '', '', 2, 3, 6)
screen:expect({grid=[[
## grid 1
@@ -3119,6 +3125,7 @@ describe('builtin popupmenu with ui/ext_multigrid', function()
{n: bar }|
{s: baz }|
]], float_pos={[4] = {{id = -1}, 'NW', 2, 1, 3, false, 100}}})
+ eq(true, screen.options.mousemoveevent)
meths.input_mouse('left', 'press', '', 2, 2, 6)
screen:expect({grid=[[
## grid 1
@@ -3137,6 +3144,7 @@ describe('builtin popupmenu with ui/ext_multigrid', function()
## grid 3
:let g:menustr = 'bar' |
]]})
+ eq(false, screen.options.mousemoveevent)
eq('bar', meths.get_var('menustr'))
end)
end)