Skip to content

Commit

Permalink
Merge pull request neovim#14416 from bfredl/floatorder
Browse files Browse the repository at this point in the history
ui_compositior: handle overlapping displayed floats in the same tick
  • Loading branch information
bfredl authored Apr 26, 2021
2 parents bb7d379 + eeb1099 commit ecf075e
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/nvim/ui_compositor.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width,
if (kv_A(layers, insert_at-1) == &pum_grid && (grid != &msg_grid)) {
insert_at--;
}
if (insert_at > 1 && !on_top) {
if (curwin && kv_A(layers, insert_at-1) == &curwin->w_grid_alloc
&& !on_top) {
insert_at--;
}
// not found: new grid
Expand Down
3 changes: 1 addition & 2 deletions src/nvim/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,8 @@ void ui_ext_win_position(win_T *wp)
wp->w_winrow = comp_row;
wp->w_wincol = comp_col;
bool valid = (wp->w_redr_type == 0);
bool on_top = (curwin == wp) || !curwin->w_floating;
ui_comp_put_grid(&wp->w_grid_alloc, comp_row, comp_col,
wp->w_height_outer, wp->w_width_outer, valid, on_top);
wp->w_height_outer, wp->w_width_outer, valid, false);
ui_check_cursor_grid(wp->w_grid_alloc.handle);
wp->w_grid_alloc.focusable = wp->w_float_config.focusable;
if (!valid) {
Expand Down
210 changes: 210 additions & 0 deletions test/functional/ui/float_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6017,6 +6017,216 @@ describe('float window', function()
]])
end
end)

it("correctly orders multiple opened floats (current last)", function()
local buf = meths.create_buf(false,false)
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5})
meths.win_set_option(win, "winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg")

if multigrid then
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[3:----------------------------------------]|
## grid 2
^ |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
## grid 3
|
## grid 4
{7: }|
{7:~ }|
]], float_pos={
[4] = { { id = 1001 }, "NW", 1, 2, 5, true };
}, win_viewport={
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0};
[4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0};
}}
else
screen:expect{grid=[[
^ |
{0:~ }|
{0:~ }{7: }{0: }|
{0:~ }{7:~ }{0: }|
{0:~ }|
{0:~ }|
|
]]}
end

exec_lua [[
local buf = vim.api.nvim_create_buf(false,false)
local win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8})
vim.api.nvim_win_set_option(win, "winhl", "EndOfBuffer:Normal")
buf = vim.api.nvim_create_buf(false,false)
win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10})
vim.api.nvim_win_set_option(win, "winhl", "Normal:Search,EndOfBuffer:Search")
]]

if multigrid then
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[3:----------------------------------------]|
## grid 2
|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
## grid 3
|
## grid 4
{7: }|
{7:~ }|
## grid 5
{1: }|
{1:~ }|
## grid 6
{17:^ }|
{17:~ }|
]], float_pos={
[4] = { { id = 1001 }, "NW", 1, 2, 5, true };
[5] = { { id = 1002 }, "NW", 1, 3, 8, true };
[6] = { { id = 1003 }, "NW", 1, 4, 10, true };
}, win_viewport={
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0};
[4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0};
[5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0};
[6] = {win = {id = 1003}, topline = 0, botline = 2, curline = 0, curcol = 0};
}}
else
screen:expect{grid=[[
|
{0:~ }|
{0:~ }{7: }{0: }|
{0:~ }{7:~ }{1: }{7: }{0: }|
{0:~ }{1:~ }{17:^ }{1: }{0: }|
{0:~ }{17:~ }{0: }|
|
]]}
end
end)

it("correctly orders multiple opened floats (non-current last)", function()
local buf = meths.create_buf(false,false)
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5})
meths.win_set_option(win, "winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg")

if multigrid then
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[3:----------------------------------------]|
## grid 2
^ |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
## grid 3
|
## grid 4
{7: }|
{7:~ }|
]], float_pos={
[4] = { { id = 1001 }, "NW", 1, 2, 5, true };
}, win_viewport={
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0};
[4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0};
}}
else
screen:expect{grid=[[
^ |
{0:~ }|
{0:~ }{7: }{0: }|
{0:~ }{7:~ }{0: }|
{0:~ }|
{0:~ }|
|
]]}
end

exec_lua [[
local buf = vim.api.nvim_create_buf(false,false)
local win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10})
vim.api.nvim_win_set_option(win, "winhl", "Normal:Search,EndOfBuffer:Search")
buf = vim.api.nvim_create_buf(false,false)
win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8})
vim.api.nvim_win_set_option(win, "winhl", "EndOfBuffer:Normal")
]]

if multigrid then
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[3:----------------------------------------]|
## grid 2
|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
## grid 3
|
## grid 4
{7: }|
{7:~ }|
## grid 5
{17:^ }|
{17:~ }|
## grid 6
{1: }|
{1:~ }|
]], float_pos={
[4] = { { id = 1001 }, "NW", 1, 2, 5, true };
[5] = { { id = 1002 }, "NW", 1, 4, 10, true };
[6] = { { id = 1003 }, "NW", 1, 3, 8, true };
}, win_viewport={
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0};
[4] = {win = {id = 1001}, topline = 0, botline = 2, curline = 0, curcol = 0};
[5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0};
[6] = {win = {id = 1003}, topline = 0, botline = 2, curline = 0, curcol = 0};
}}
else
screen:expect{grid=[[
|
{0:~ }|
{0:~ }{7: }{0: }|
{0:~ }{7:~ }{1: }{7: }{0: }|
{0:~ }{1:~ }{17:^ }{1: }{0: }|
{0:~ }{17:~ }{0: }|
|
]]}
end
end)
end

describe('with ext_multigrid', function()
Expand Down

0 comments on commit ecf075e

Please sign in to comment.