fix(float): fix mouse drag position if float window turned to a split

This commit is contained in:
zeertzjq 2022-05-28 12:01:44 +08:00
parent 63f63dd2b7
commit 63f6ecd419
2 changed files with 125 additions and 3 deletions

View File

@ -1941,7 +1941,7 @@ static void win_totop(int size, int flags)
} else { } else {
// No longer a float, a non-multigrid UI shouldn't draw it as such // No longer a float, a non-multigrid UI shouldn't draw it as such
ui_call_win_hide(curwin->w_grid_alloc.handle); ui_call_win_hide(curwin->w_grid_alloc.handle);
win_free_grid(curwin, false); win_free_grid(curwin, true);
} }
} else { } else {
// Remove the window and frame from the tree of frames. // Remove the window and frame from the tree of frames.
@ -5179,8 +5179,7 @@ void win_free_grid(win_T *wp, bool reinit)
} }
grid_free(&wp->w_grid_alloc); grid_free(&wp->w_grid_alloc);
if (reinit) { if (reinit) {
// if a float is turned into a split and back into a float, the grid // if a float is turned into a split, the grid data structure will be reused
// data structure will be reused
memset(&wp->w_grid_alloc, 0, sizeof(wp->w_grid_alloc)); memset(&wp->w_grid_alloc, 0, sizeof(wp->w_grid_alloc));
} }
} }

View File

@ -6726,6 +6726,7 @@ describe('float window', function()
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
[5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3}; [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
}} }}
meths.input_mouse('left', 'press', '', 5, 0, 0) meths.input_mouse('left', 'press', '', 5, 0, 0)
screen:expect{grid=[[ screen:expect{grid=[[
## grid 1 ## grid 1
@ -6755,6 +6756,7 @@ describe('float window', function()
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
[5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3}; [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
}} }}
meths.input_mouse('left', 'drag', '', 5, 1, 2) meths.input_mouse('left', 'drag', '', 5, 1, 2)
screen:expect{grid=[[ screen:expect{grid=[[
## grid 1 ## grid 1
@ -6854,6 +6856,7 @@ describe('float window', function()
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
[5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3}; [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
}} }}
meths.input_mouse('left', 'press', '', 5, 1, 1) meths.input_mouse('left', 'press', '', 5, 1, 1)
screen:expect{grid=[[ screen:expect{grid=[[
## grid 1 ## grid 1
@ -6885,6 +6888,7 @@ describe('float window', function()
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
[5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3}; [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
}} }}
meths.input_mouse('left', 'drag', '', 5, 2, 3) meths.input_mouse('left', 'drag', '', 5, 2, 3)
screen:expect{grid=[[ screen:expect{grid=[[
## grid 1 ## grid 1
@ -6986,6 +6990,7 @@ describe('float window', function()
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
[5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3}; [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
}} }}
meths.input_mouse('left', 'press', '', 5, 1, 0) meths.input_mouse('left', 'press', '', 5, 1, 0)
screen:expect{grid=[[ screen:expect{grid=[[
## grid 1 ## grid 1
@ -7016,6 +7021,7 @@ describe('float window', function()
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1}; [2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
[5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3}; [5] = {win = {id = 1002}, topline = 0, botline = 3, curline = 0, curcol = 0, linecount = 3};
}} }}
meths.input_mouse('left', 'drag', '', 5, 2, 2) meths.input_mouse('left', 'drag', '', 5, 2, 2)
screen:expect{grid=[[ screen:expect{grid=[[
## grid 1 ## grid 1
@ -7081,6 +7087,123 @@ describe('float window', function()
end end
end) end)
it('left drag changes visual selection if float window is turned into a split', function()
local buf = meths.create_buf(false,false)
meths.buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'})
meths.open_win(buf, true, {relative='editor', width=20, height=3, row=2, col=5})
command('wincmd L')
if multigrid then
screen:expect([[
## grid 1
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
{5:[No Name] }{4:[No Name] [+] }|
[3:----------------------------------------]|
## grid 2
|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
## grid 3
|
## grid 5
^foo |
bar |
baz |
{0:~ }|
{0:~ }|
]])
meths.input_mouse('left', 'press', '', 5, 2, 2)
screen:expect([[
## grid 1
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
{5:[No Name] }{4:[No Name] [+] }|
[3:----------------------------------------]|
## grid 2
|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
## grid 3
|
## grid 5
foo |
bar |
ba^z |
{0:~ }|
{0:~ }|
]])
meths.input_mouse('left', 'drag', '', 5, 1, 1)
screen:expect([[
## grid 1
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
[2:-------------------]{5:│}[5:--------------------]|
{5:[No Name] }{4:[No Name] [+] }|
[3:----------------------------------------]|
## grid 2
|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
## grid 3
{3:-- VISUAL --} |
## grid 5
foo |
b^a{27:r} |
{27:baz} |
{0:~ }|
{0:~ }|
]])
else
screen:expect([[
{5:}^foo |
{0:~ }{5:}bar |
{0:~ }{5:}baz |
{0:~ }{5:}{0:~ }|
{0:~ }{5:}{0:~ }|
{5:[No Name] }{4:[No Name] [+] }|
|
]])
meths.input_mouse('left', 'press', '', 0, 2, 22)
screen:expect([[
{5:}foo |
{0:~ }{5:}bar |
{0:~ }{5:}ba^z |
{0:~ }{5:}{0:~ }|
{0:~ }{5:}{0:~ }|
{5:[No Name] }{4:[No Name] [+] }|
|
]])
meths.input_mouse('left', 'drag', '', 0, 1, 21)
screen:expect([[
{5:}foo |
{0:~ }{5:}b^a{27:r} |
{0:~ }{5:}{27:baz} |
{0:~ }{5:}{0:~ }|
{0:~ }{5:}{0:~ }|
{5:[No Name] }{4:[No Name] [+] }|
{3:-- VISUAL --} |
]])
end
end)
it("'winblend' option", function() it("'winblend' option", function()
screen:try_resize(50,9) screen:try_resize(50,9)
screen:set_default_attr_ids({ screen:set_default_attr_ids({