feat(api): nvim_open_win() relative to tabline and laststatus #32006

Problem:  Anchoring a floating window to the tabline and laststatus is
          cumbersome; requiring autocommands and looping over all
          windows/tabpages.
Solution: Add new "tabline" and "laststatus" options to the `relative`
          field of nvim_open_win() to place a window relative to.
This commit is contained in:
luukvbaal
2025-01-14 14:02:46 +01:00
committed by GitHub
parent e8ddb7a469
commit 25d8c3a5ad
8 changed files with 133 additions and 12 deletions

View File

@ -1012,6 +1012,97 @@ describe('float window', function()
end)
end)
it('placed relative to tabline and laststatus', function()
local screen = Screen.new(20, 10)
screen:add_extra_attr_ids({ [100] = { bold = true, foreground = Screen.colors.Magenta } })
command('set showtabline=1 laststatus=1')
api.nvim_open_win(0, false, {
relative = 'laststatus',
border = 'single',
anchor = 'SE',
width = 5,
height = 1,
row = 0,
col = 1000,
})
local tabwin = api.nvim_open_win(0, false, {
relative = 'tabline',
border = 'single',
width = 5,
height = 1,
row = 0,
col = 1000,
})
screen:expect([[
^ {2:┌─────┐}|
{1:~ }{2:│}{4: }{2:│}|
{1:~ }{2:└─────┘}|
{1:~ }|*3
{1:~ }{2:┌─────┐}|
{1:~ }{2:│}{4: }{2:│}|
{1:~ }{2:└─────┘}|
|
]])
command('tabnew | tabnext')
screen:expect([[
{5: }{100:3}{5: Name] }{24: No Name]X}|
^ {2:┌─────┐}|
{1:~ }{2:│}{4: }{2:│}|
{1:~ }{2:└─────┘}|
{1:~ }|*2
{1:~ }{2:┌─────┐}|
{1:~ }{2:│}{4: }{2:│}|
{1:~ }{2:└─────┘}|
|
]])
command('vsplit')
screen:expect([[
{5: }{100:4}{5: Name] }{24: No Name]X}|
^ {2:┌─────┐}|
{1:~ }{2:│}{4: }{2:│}|
{1:~ }{2:└─────┘}|
{1:~ }{2:│}{1:~}|
{1:~ }{2:┌─────┐}|
{1:~ }{2:│}{4: }{2:│}|
{1:~ }{2:└─────┘}|
{3:[No Name] }{2:<}|
|
]])
command('quit')
api.nvim_win_set_config(tabwin, {
relative = 'tabline',
border = 'single',
width = 5,
height = 1,
row = 1,
col = 0,
})
screen:expect([[
{5: }{100:3}{5: Name] }{24: No Name]X}|
^ |
{2:┌─────┐}{1: }|
{2:│}{4: }{2:│}{1: }|
{2:└─────┘}{1: }|
{1:~ }|
{1:~ }{2:┌─────┐}|
{1:~ }{2:│}{4: }{2:│}|
{1:~ }{2:└─────┘}|
|
]])
command('tabonly')
screen:expect([[
^ |
{2:┌─────┐}{1: }|
{2:│}{4: }{2:│}{1: }|
{2:└─────┘}{1: }|
{1:~ }|*2
{1:~ }{2:┌─────┐}|
{1:~ }{2:│}{4: }{2:│}|
{1:~ }{2:└─────┘}|
|
]])
end)
local function with_ext_multigrid(multigrid)
local screen, attrs
before_each(function()