mirror of
https://github.com/neovim/neovim.git
synced 2025-09-20 18:28:19 +00:00
feat(ui): support grid=0 in nvim_input_mouse #32535
Problem: Multigrid UIs have to find out which window to send the input by using the Nvim focus rules, which are not fully documented. Furthermore,`getmousepos()` has several problems when multigrid is enabled, with the main one being that screenrow and screencol are window relative instead of screen relative, due to the fact that the UI don't send any absolute coordinates. Solution: Allow passing 0 as grid to `nvim_input_mouse`, with absolute coordinates, which lets nvim determine the actual window to send the mouse input to. This works as long as nvim is in charge of the window positioning. If the UI repositions or resizes the windows, it can still pass the grid it determines like before.
This commit is contained in:
@@ -971,7 +971,7 @@ describe('float window', function()
|
||||
api.nvim_win_set_config(win, api.nvim_win_get_config(win))
|
||||
end)
|
||||
|
||||
local function with_ext_multigrid(multigrid)
|
||||
local function with_ext_multigrid(multigrid, send_mouse_grid)
|
||||
local screen, attrs
|
||||
before_each(function()
|
||||
screen = Screen.new(40, 7, { ext_multigrid = multigrid })
|
||||
@@ -6164,8 +6164,12 @@ describe('float window', function()
|
||||
end)
|
||||
|
||||
local function test_float_mouse_focus()
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 0, 0)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
|
||||
end
|
||||
if multigrid then
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -6183,7 +6187,6 @@ describe('float window', function()
|
||||
float_pos = expected_pos,
|
||||
}
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
|
||||
screen:expect([[
|
||||
x |
|
||||
{0:~ }|
|
||||
@@ -6194,8 +6197,12 @@ describe('float window', function()
|
||||
]])
|
||||
end
|
||||
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 2, 0, 0)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
|
||||
end
|
||||
if multigrid then
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -6213,7 +6220,6 @@ describe('float window', function()
|
||||
float_pos = expected_pos,
|
||||
}
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
|
||||
screen:expect([[
|
||||
^x |
|
||||
{0:~ }|
|
||||
@@ -6237,27 +6243,53 @@ describe('float window', function()
|
||||
local function test_float_mouse_no_focus()
|
||||
api.nvim_buf_set_lines(0, -1, -1, true, { 'a' })
|
||||
expected_pos[4][6] = false
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 0, 0)
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
[2:----------------------------------------]|*6
|
||||
[3:----------------------------------------]|
|
||||
## grid 2
|
||||
^x |
|
||||
a |
|
||||
{0:~ }|*4
|
||||
## grid 3
|
||||
|
|
||||
## grid 4
|
||||
{1:y }|
|
||||
{2:~ }|
|
||||
]],
|
||||
float_pos = expected_pos,
|
||||
}
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
|
||||
end
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
-- Sending input to grid 4 is a user error, you are not supposed to pass a grid
|
||||
-- that isn't focusable. In this case, nothing happens and the input is not passed
|
||||
-- through to grid 4, like normally happens when you pass grid 0.
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
[2:----------------------------------------]|*6
|
||||
[3:----------------------------------------]|
|
||||
## grid 2
|
||||
^x |
|
||||
a |
|
||||
{0:~ }|*4
|
||||
## grid 3
|
||||
|
|
||||
## grid 4
|
||||
{1:y }|
|
||||
{2:~ }|
|
||||
]],
|
||||
float_pos = expected_pos,
|
||||
}
|
||||
else
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
[2:----------------------------------------]|*6
|
||||
[3:----------------------------------------]|
|
||||
## grid 2
|
||||
x |
|
||||
^a |
|
||||
{0:~ }|*4
|
||||
## grid 3
|
||||
|
|
||||
## grid 4
|
||||
{1:y }|
|
||||
{2:~ }|
|
||||
]],
|
||||
float_pos = expected_pos,
|
||||
}
|
||||
end
|
||||
else
|
||||
screen:expect([[
|
||||
x |
|
||||
^a |
|
||||
@@ -6268,8 +6300,12 @@ describe('float window', function()
|
||||
]])
|
||||
end
|
||||
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 2, 0, 0)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
|
||||
end
|
||||
if multigrid then
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -6289,7 +6325,6 @@ describe('float window', function()
|
||||
unchanged = true,
|
||||
}
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
|
||||
screen:expect([[
|
||||
^x |
|
||||
a |
|
||||
@@ -7959,7 +7994,11 @@ describe('float window', function()
|
||||
},
|
||||
}
|
||||
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 0, 0)
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 0, 0)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
|
||||
end
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -7982,7 +8021,11 @@ describe('float window', function()
|
||||
},
|
||||
}
|
||||
|
||||
api.nvim_input_mouse('left', 'drag', '', 4, 1, 2)
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'drag', '', 4, 1, 2)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'drag', '', 0, 3, 7)
|
||||
end
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -8074,7 +8117,11 @@ describe('float window', function()
|
||||
},
|
||||
}
|
||||
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 1, 1)
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 1, 1)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 1, 6)
|
||||
end
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -8099,7 +8146,11 @@ describe('float window', function()
|
||||
},
|
||||
}
|
||||
|
||||
api.nvim_input_mouse('left', 'drag', '', 4, 2, 3)
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'drag', '', 4, 2, 3)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'drag', '', 0, 2, 8)
|
||||
end
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -8193,7 +8244,11 @@ describe('float window', function()
|
||||
},
|
||||
}
|
||||
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 1, 0)
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 1, 0)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 5)
|
||||
end
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -8217,7 +8272,11 @@ describe('float window', function()
|
||||
},
|
||||
}
|
||||
|
||||
api.nvim_input_mouse('left', 'drag', '', 4, 2, 2)
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'drag', '', 4, 2, 2)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'drag', '', 0, 3, 7)
|
||||
end
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -8304,7 +8363,11 @@ describe('float window', function()
|
||||
{0:~ }|*2
|
||||
]])
|
||||
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 2, 2)
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 2, 2)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 22)
|
||||
end
|
||||
screen:expect([[
|
||||
## grid 1
|
||||
[2:-------------------]{5:│}[4:--------------------]|*5
|
||||
@@ -8322,7 +8385,11 @@ describe('float window', function()
|
||||
{0:~ }|*2
|
||||
]])
|
||||
|
||||
api.nvim_input_mouse('left', 'drag', '', 4, 1, 1)
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'drag', '', 4, 1, 1)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'drag', '', 0, 1, 21)
|
||||
end
|
||||
screen:expect([[
|
||||
## grid 1
|
||||
[2:-------------------]{5:│}[4:--------------------]|*5
|
||||
@@ -8409,21 +8476,21 @@ describe('float window', function()
|
||||
}
|
||||
end
|
||||
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 3, 1)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 3, 6)
|
||||
end
|
||||
eq({ 0, 3, 1, 0, 1 }, fn.getcurpos())
|
||||
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 3, 2)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 3, 7)
|
||||
end
|
||||
eq({ 0, 3, 1, 0, 2 }, fn.getcurpos())
|
||||
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 3, 10)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 3, 15)
|
||||
@@ -8470,8 +8537,12 @@ describe('float window', function()
|
||||
}
|
||||
end
|
||||
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 2, 1)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 6)
|
||||
end
|
||||
if multigrid then
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -8496,7 +8567,6 @@ describe('float window', function()
|
||||
},
|
||||
}
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 6)
|
||||
screen:expect {
|
||||
grid = [[
|
||||
{5:┌────────────────────┐} |
|
||||
@@ -8510,21 +8580,21 @@ describe('float window', function()
|
||||
}
|
||||
end
|
||||
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 2, 2)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 7)
|
||||
end
|
||||
eq({ 0, 2, 1, 0, 1 }, fn.getcurpos())
|
||||
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 2, 3)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 8)
|
||||
end
|
||||
eq({ 0, 2, 1, 0, 2 }, fn.getcurpos())
|
||||
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('left', 'press', '', 4, 2, 11)
|
||||
else
|
||||
api.nvim_input_mouse('left', 'press', '', 0, 2, 16)
|
||||
@@ -8840,8 +8910,12 @@ describe('float window', function()
|
||||
end
|
||||
|
||||
-- Test scrolling by mouse
|
||||
if multigrid then
|
||||
if send_mouse_grid then
|
||||
api.nvim_input_mouse('wheel', 'down', '', 4, 2, 2)
|
||||
else
|
||||
api.nvim_input_mouse('wheel', 'down', '', 0, 4, 7)
|
||||
end
|
||||
if multigrid then
|
||||
screen:expect {
|
||||
grid = [[
|
||||
## grid 1
|
||||
@@ -8865,7 +8939,6 @@ describe('float window', function()
|
||||
float_pos = { [4] = { 1001, 'NW', 1, 2, 5, true, 50, 1, 2, 5 } },
|
||||
}
|
||||
else
|
||||
api.nvim_input_mouse('wheel', 'down', '', 0, 4, 7)
|
||||
screen:expect([[
|
||||
Ut enim ad minim veniam, quis nostrud |
|
||||
exercitation ullamco laboris nisi ut aliquip ex |
|
||||
@@ -11047,10 +11120,15 @@ describe('float window', function()
|
||||
end)
|
||||
end
|
||||
|
||||
describe('with ext_multigrid', function()
|
||||
with_ext_multigrid(true)
|
||||
describe('with ext_multigrid and actual mouse grid', function()
|
||||
with_ext_multigrid(true, true)
|
||||
end)
|
||||
|
||||
describe('with ext_multigrid and mouse grid 0', function()
|
||||
with_ext_multigrid(true, false)
|
||||
end)
|
||||
|
||||
describe('without ext_multigrid', function()
|
||||
with_ext_multigrid(false)
|
||||
with_ext_multigrid(false, false)
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user