Skip to content

Commit

Permalink
fix(multigrid): #15075 mouse events crash neovim
Browse files Browse the repository at this point in the history
  • Loading branch information
yatli committed Sep 7, 2021
1 parent db695cc commit 28ac6c0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/nvim/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,14 +723,20 @@ int mouse_check_fold(void)
int click_row = mouse_row;
int click_col = mouse_col;
int mouse_char = ' ';
int max_row = Rows;
int max_col = Columns;
int multigrid = ui_has(kUIMultigrid);

win_T *wp;

wp = mouse_find_win(&click_grid, &click_row, &click_col);
if (wp && multigrid) {
max_row = wp->w_grid_alloc.Rows;
max_col = wp->w_grid_alloc.Columns;
}

if (wp && mouse_row >= 0 && mouse_row < Rows
&& mouse_col >= 0 && mouse_col <= Columns) {
int multigrid = ui_has(kUIMultigrid);
if (wp && mouse_row >= 0 && mouse_row < max_row
&& mouse_col >= 0 && mouse_col < max_col) {
ScreenGrid *gp = multigrid ? &wp->w_grid_alloc : &default_grid;
int fdc = win_fdccol_count(wp);
int row = multigrid && mouse_grid == 0 ? click_row : mouse_row;
Expand Down
88 changes: 88 additions & 0 deletions test/functional/ui/multigrid_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2220,4 +2220,92 @@ describe('ext_multigrid', function()
[4] = {win = {id = 1001}, topline = 4, botline = 8, curline = 4, curcol = 38},
}}
end)

it('does not crash when dragging mouse across grid boundary', function()
screen:try_resize(48, 8)
screen:expect{grid=[[
## grid 1
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
{11:[No Name] }|
[3:------------------------------------------------]|
## grid 2
^ |
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
{1:~ }|
## grid 3
|
]], win_viewport={
[2] = {win = { id = 1000 }, topline = 0, botline = 2, curline = 0, curcol = 0}
}}
insert([[
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex
ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa
qui officia deserunt mollit anim id est
laborum.]])

screen:expect{grid=[[
## grid 1
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
{11:[No Name] [+] }|
[3:------------------------------------------------]|
## grid 2
ea commodo consequat. Duis aute irure dolor in |
reprehenderit in voluptate velit esse cillum |
dolore eu fugiat nulla pariatur. Excepteur sint |
occaecat cupidatat non proident, sunt in culpa |
qui officia deserunt mollit anim id est |
laborum^. |
## grid 3
|
]], win_viewport={
[2] = {win = {id = 1000}, topline = 5, botline = 11, curline = 10, curcol = 7},
}}

meths.input_mouse('left', 'press', '', 1,5, 1)
poke_eventloop()
meths.input_mouse('left', 'drag', '', 1, 6, 1)

screen:expect{grid=[[
## grid 1
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
[2:------------------------------------------------]|
{11:[No Name] [+] }|
[3:------------------------------------------------]|
## grid 2
reprehenderit in voluptate velit esse cillum |
dolore eu fugiat nulla pariatur. Excepteur sint |
occaecat cupidatat non proident, sunt in culpa |
qui officia deserunt mollit anim id est |
l^aborum. |
{1:~ }|
## grid 3
{7:-- VISUAL --} |
]], win_viewport={
[2] = {win = {id = 1000}, topline = 6, botline = 12, curline = 10, curcol = 1},
}}
end)
end)

0 comments on commit 28ac6c0

Please sign in to comment.