mirror of
https://github.com/neovim/neovim.git
synced 2025-11-13 13:59:16 +00:00
feat(float): add winborder option (#31074)
Problem: There is currently no global option to define the default border style for floating windows. This leads to repetitive code when developers need consistent styling across multiple floating windows. Solution: Introduce a global option winborder to specify the default border style for floating windows. When a floating window is created without explicitly specifying a border style, the value of the winborder option will be used. This simplifies configuration and ensures consistency in floating window appearance. Co-authored-by: Gregory Anders <greg@gpanders.com>
This commit is contained in:
@@ -9909,6 +9909,253 @@ describe('float window', function()
|
||||
]])
|
||||
eq({"%f", ""}, res)
|
||||
end)
|
||||
|
||||
it('winborder option', function()
|
||||
local buf = api.nvim_create_buf(false,false)
|
||||
local config = {relative='editor', width=4, height=4, row=2, col=2}
|
||||
command('set winborder=single')
|
||||
api.nvim_open_win(buf, true, config)
|
||||
if multigrid then
|
||||
screen:expect({
|
||||
grid = [[
|
||||
## grid 1
|
||||
[2:----------------------------------------]|*6
|
||||
[3:----------------------------------------]|
|
||||
## grid 2
|
||||
|
|
||||
{0:~ }|*5
|
||||
## grid 3
|
||||
|
|
||||
## grid 4
|
||||
{5:┌────┐}|
|
||||
{5:│}{1:^ }{5:│}|
|
||||
{5:│}{2:~ }{5:│}|*3
|
||||
{5:└────┘}|
|
||||
]], float_pos={
|
||||
[4] = {1001, "NW", 1, 2, 2, true, 50};
|
||||
}, win_viewport={
|
||||
[2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
|
||||
[4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
|
||||
}, win_viewport_margins={
|
||||
[2] = {
|
||||
bottom = 0,
|
||||
left = 0,
|
||||
right = 0,
|
||||
top = 0,
|
||||
win = 1000
|
||||
},
|
||||
[4] = {
|
||||
bottom = 1,
|
||||
left = 1,
|
||||
right = 1,
|
||||
top = 1,
|
||||
win = 1001
|
||||
}
|
||||
}
|
||||
})
|
||||
else
|
||||
screen:expect({
|
||||
grid = [[
|
||||
{5:┌────┐} |
|
||||
{0:~ }{5:│}{1:^ }{5:│}{0: }|
|
||||
{0:~ }{5:│}{2:~ }{5:│}{0: }|*3
|
||||
{0:~ }{5:└────┘}{0: }|
|
||||
|
|
||||
]]
|
||||
})
|
||||
end
|
||||
command('fclose')
|
||||
|
||||
command('set winborder=double')
|
||||
api.nvim_open_win(buf, true, config)
|
||||
if multigrid then
|
||||
screen:expect({
|
||||
grid = [[
|
||||
## grid 1
|
||||
[2:----------------------------------------]|*6
|
||||
[3:----------------------------------------]|
|
||||
## grid 2
|
||||
|
|
||||
{0:~ }|*5
|
||||
## grid 3
|
||||
|
|
||||
## grid 5
|
||||
{5:╔════╗}|
|
||||
{5:║}{1:^ }{5:║}|
|
||||
{5:║}{2:~ }{5:║}|*3
|
||||
{5:╚════╝}|
|
||||
]], float_pos={
|
||||
[5] = {1002, "NW", 1, 2, 2, true, 50};
|
||||
}, win_viewport={
|
||||
[2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
|
||||
[5] = {win = 1002, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
|
||||
}, win_viewport_margins={
|
||||
[2] = {
|
||||
bottom = 0,
|
||||
left = 0,
|
||||
right = 0,
|
||||
top = 0,
|
||||
win = 1000
|
||||
},
|
||||
[5] = {
|
||||
bottom = 1,
|
||||
left = 1,
|
||||
right = 1,
|
||||
top = 1,
|
||||
win = 1002
|
||||
}
|
||||
}
|
||||
})
|
||||
else
|
||||
screen:expect({
|
||||
grid = [[
|
||||
{5:╔════╗} |
|
||||
{0:~ }{5:║}{1:^ }{5:║}{0: }|
|
||||
{0:~ }{5:║}{2:~ }{5:║}{0: }|*3
|
||||
{0:~ }{5:╚════╝}{0: }|
|
||||
|
|
||||
]]
|
||||
})
|
||||
end
|
||||
command('fclose!')
|
||||
|
||||
command('set winborder=none')
|
||||
api.nvim_buf_set_lines(buf, 0, -1, false, {'none border'})
|
||||
api.nvim_open_win(buf, true, config)
|
||||
if multigrid then
|
||||
screen:expect({
|
||||
grid = [[
|
||||
## grid 1
|
||||
[2:----------------------------------------]|*6
|
||||
[3:----------------------------------------]|
|
||||
## grid 2
|
||||
|
|
||||
{0:~ }|*5
|
||||
## grid 3
|
||||
|
|
||||
## grid 6
|
||||
{1:^none}|
|
||||
{1: bor}|
|
||||
{1:der }|
|
||||
{2:~ }|
|
||||
]],
|
||||
win_pos = {
|
||||
[2] = {
|
||||
height = 6,
|
||||
startcol = 0,
|
||||
startrow = 0,
|
||||
width = 40,
|
||||
win = 1000
|
||||
}
|
||||
},
|
||||
float_pos = {
|
||||
[6] = {1003, "NW", 1, 2, 2, true, 50};
|
||||
},
|
||||
win_viewport = {
|
||||
[2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
|
||||
[6] = {win = 1003, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
|
||||
},
|
||||
win_viewport_margins = {
|
||||
[2] = {
|
||||
bottom = 0,
|
||||
left = 0,
|
||||
right = 0,
|
||||
top = 0,
|
||||
win = 1000
|
||||
},
|
||||
[6] = {
|
||||
bottom = 0,
|
||||
left = 0,
|
||||
right = 0,
|
||||
top = 0,
|
||||
win = 1003
|
||||
}
|
||||
},
|
||||
})
|
||||
else
|
||||
screen:expect([[
|
||||
|
|
||||
{0:~ }|
|
||||
{0:~ }{1:^none}{0: }|
|
||||
{0:~ }{1: bor}{0: }|
|
||||
{0:~ }{1:der }{0: }|
|
||||
{0:~ }{2:~ }{0: }|
|
||||
|
|
||||
]])
|
||||
end
|
||||
command('fclose!')
|
||||
|
||||
-- respect config.border
|
||||
command('set winborder=rounded')
|
||||
config.border = 'single'
|
||||
api.nvim_open_win(buf, false, config)
|
||||
if multigrid then
|
||||
screen:expect({
|
||||
grid = [[
|
||||
## grid 1
|
||||
[2:----------------------------------------]|*6
|
||||
[3:----------------------------------------]|
|
||||
## grid 2
|
||||
^ |
|
||||
{0:~ }|*5
|
||||
## grid 3
|
||||
|
|
||||
## grid 7
|
||||
{5:┌────┐}|
|
||||
{5:│}{1:none}{5:│}|
|
||||
{5:│}{1: bor}{5:│}|
|
||||
{5:│}{1:der }{5:│}|
|
||||
{5:│}{2:~ }{5:│}|
|
||||
{5:└────┘}|
|
||||
]],
|
||||
win_pos = {
|
||||
[2] = {
|
||||
height = 6,
|
||||
startcol = 0,
|
||||
startrow = 0,
|
||||
width = 40,
|
||||
win = 1000
|
||||
}
|
||||
},
|
||||
float_pos = {
|
||||
[7] = {1004, "NW", 1, 2, 2, true, 50};
|
||||
},
|
||||
win_viewport = {
|
||||
[2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
|
||||
[7] = {win = 1004, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0};
|
||||
},
|
||||
win_viewport_margins = {
|
||||
[2] = {
|
||||
bottom = 0,
|
||||
left = 0,
|
||||
right = 0,
|
||||
top = 0,
|
||||
win = 1000
|
||||
},
|
||||
[7] = {
|
||||
bottom = 1,
|
||||
left = 1,
|
||||
right = 1,
|
||||
top = 1,
|
||||
win = 1004
|
||||
}
|
||||
},
|
||||
})
|
||||
else
|
||||
screen:expect([[
|
||||
^ {5:┌────┐} |
|
||||
{0:~ }{5:│}{1:none}{5:│}{0: }|
|
||||
{0:~ }{5:│}{1: bor}{5:│}{0: }|
|
||||
{0:~ }{5:│}{1:der }{5:│}{0: }|
|
||||
{0:~ }{5:│}{2:~ }{5:│}{0: }|
|
||||
{0:~ }{5:└────┘}{0: }|
|
||||
|
|
||||
]])
|
||||
end
|
||||
|
||||
-- it is currently not supported.
|
||||
eq('Vim(set):E474: Invalid argument: winborder=custom', pcall_err(command, 'set winborder=custom'))
|
||||
end)
|
||||
end
|
||||
|
||||
describe('with ext_multigrid', function()
|
||||
|
||||
Reference in New Issue
Block a user