diff options
author | Yatao Li <yatli@microsoft.com> | 2021-07-15 02:53:58 +0800 |
---|---|---|
committer | Yatao Li <yatli@microsoft.com> | 2021-09-08 01:57:40 +0800 |
commit | 28ac6c00e6f61d40f082af3ae3db380d7951acee (patch) | |
tree | bbcb3379a779aeb6b77772c3eed28d99e3466060 | |
parent | db695cc4cafa6c26eb71a183cc73a167b842731e (diff) | |
download | rneovim-28ac6c00e6f61d40f082af3ae3db380d7951acee.tar.gz rneovim-28ac6c00e6f61d40f082af3ae3db380d7951acee.tar.bz2 rneovim-28ac6c00e6f61d40f082af3ae3db380d7951acee.zip |
fix(multigrid): #15075 mouse events crash neovim
-rw-r--r-- | src/nvim/mouse.c | 12 | ||||
-rw-r--r-- | test/functional/ui/multigrid_spec.lua | 88 |
2 files changed, 97 insertions, 3 deletions
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 6c25525936..c599f4ea97 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -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; diff --git a/test/functional/ui/multigrid_spec.lua b/test/functional/ui/multigrid_spec.lua index 719e2ee82a..03cb43a7d1 100644 --- a/test/functional/ui/multigrid_spec.lua +++ b/test/functional/ui/multigrid_spec.lua @@ -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) |