Merge pull request #15091 from yatli/mouse_drag_fix

fix #15075 (mouse crash in multigrid)
This commit is contained in:
Björn Linse 2021-09-09 17:37:59 +02:00 committed by GitHub
commit 422198cde6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 3 deletions

View File

@ -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;

View File

@ -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)