feat(float): 'statusline' in floating windows #36521

Problem:
Can't show 'statusline' in floating windows.

Solution:
Use window-local 'statusline' to control floating window statusline visibility.
This commit is contained in:
glepnir
2025-11-27 01:10:45 +08:00
committed by GitHub
parent 23d0d4c92a
commit 8a626e5c4a
13 changed files with 414 additions and 254 deletions

View File

@@ -1758,64 +1758,11 @@ function vim.api.nvim_open_term(buffer, opts) end
--- @param buffer integer Buffer to display, or 0 for current buffer
--- @param enter boolean Enter the window (make it the current window)
--- @param config vim.api.keyset.win_config Map defining the window configuration. Keys:
--- - relative: Sets the window layout to "floating", placed at (row,col)
--- coordinates relative to:
--- - "cursor" Cursor position in current window.
--- - "editor" The global editor grid.
--- - "laststatus" 'laststatus' if present, or last row.
--- - "mouse" Mouse position.
--- - "tabline" Tabline if present, or first row.
--- - "win" Window given by the `win` field, or current window.
--- - win: `window-ID` window to split, or relative window when creating a
--- float (relative="win").
--- - anchor: Decides which corner of the float to place at (row,col):
--- - "NW" northwest (default)
--- - "NE" northeast
--- - "SW" southwest
--- - "SE" southeast
--- - width: Window width (in character cells). Minimum of 1.
--- - height: Window height (in character cells). Minimum of 1.
--- - bufpos: Places float relative to buffer text (only when
--- relative="win"). Takes a tuple of zero-indexed `[line, column]`.
--- `row` and `col` if given are applied relative to this
--- position, else they default to:
--- - `row=1` and `col=0` if `anchor` is "NW" or "NE"
--- - `row=0` and `col=0` if `anchor` is "SW" or "SE"
--- (thus like a tooltip near the buffer text).
--- - row: Row position in units of "screen cell height", may be fractional.
--- - col: Column position in units of screen cell width, may be fractional.
--- - focusable: Enable focus by user actions (wincmds, mouse events).
--- Defaults to true. Non-focusable windows can be entered by
--- `nvim_set_current_win()`, or, when the `mouse` field is set to true,
--- by mouse events. See `focusable`.
--- - mouse: Specify how this window interacts with mouse events.
--- Defaults to `focusable` value.
--- - If false, mouse events pass through this window.
--- - If true, mouse events interact with this window normally.
--- - external: GUI should display the window as an external
--- top-level window. Currently accepts no other positioning
--- configuration together with this.
--- - zindex: Stacking order. floats with higher `zindex` go on top on
--- floats with lower indices. Must be larger than zero. The
--- following screen elements have hard-coded z-indices:
--- - 100: insert completion popupmenu
--- - 200: message scrollback
--- - 250: cmdline completion popupmenu (when wildoptions+=pum)
--- The default value for floats are 50. In general, values below 100 are
--- recommended, unless there is a good reason to overshadow builtin
--- elements.
--- - style: (optional) Configure the appearance of the window. Currently
--- only supports one value:
--- - "minimal" Nvim will display the window with many UI options
--- disabled. This is useful when displaying a temporary
--- float where the text should not be edited. Disables
--- 'number', 'relativenumber', 'cursorline', 'cursorcolumn',
--- 'foldcolumn', 'spell' and 'list' options. 'signcolumn'
--- is changed to `auto` and 'colorcolumn' is cleared.
--- 'statuscolumn' is changed to empty. The end-of-buffer
--- region is hidden by setting `eob` flag of
--- 'fillchars' to a space char, and clearing the
--- `hl-EndOfBuffer` region in 'winhighlight'.
--- - border: (`string|string[]`) (defaults to 'winborder' option) Window border. The string form
--- accepts the same values as the 'winborder' option. The array form must have a length of
--- eight or any divisor of eight, specifying the chars that form the border in a clockwise
@@ -1839,30 +1786,83 @@ function vim.api.nvim_open_term(buffer, opts) end
--- [ "", "", "", ">", "", "", "", "<" ]
--- ```
--- By default, `hl-FloatBorder` highlight is used, which links to `hl-WinSeparator` when not
--- defined. Each border side can specify an optional highlight:
--- defined. Each border side can specify an optional highlight:
--- ```
--- [ ["+", "MyCorner"], ["x", "MyBorder"] ].
--- ```
--- - title: (optional) Title in window border, string or list.
--- List should consist of `[text, highlight]` tuples.
--- If string, or a tuple lacks a highlight, the default highlight group is `FloatTitle`.
--- - title_pos: Title position. Must be set with `title` option.
--- Value can be one of "left", "center", or "right".
--- Default is `"left"`.
--- - footer: (optional) Footer in window border, string or list.
--- List should consist of `[text, highlight]` tuples.
--- If string, or a tuple lacks a highlight, the default highlight group is `FloatFooter`.
--- - footer_pos: Footer position. Must be set with `footer` option.
--- Value can be one of "left", "center", or "right".
--- Default is `"left"`.
--- - noautocmd: Block all autocommands for the duration of the call. Cannot be changed by
--- `nvim_win_set_config()`.
--- - bufpos: Places float relative to buffer text (only when
--- relative="win"). Takes a tuple of zero-indexed `[line, column]`.
--- `row` and `col` if given are applied relative to this
--- position, else they default to:
--- - `row=1` and `col=0` if `anchor` is "NW" or "NE"
--- - `row=0` and `col=0` if `anchor` is "SW" or "SE"
--- (thus like a tooltip near the buffer text).
--- - col: Column position in units of screen cell width, may be fractional.
--- - external: GUI should display the window as an external
--- top-level window. Currently accepts no other positioning
--- configuration together with this.
--- - fixed: If true when anchor is NW or SW, the float window
--- would be kept fixed even if the window would be truncated.
--- - focusable: Enable focus by user actions (wincmds, mouse events).
--- Defaults to true. Non-focusable windows can be entered by
--- `nvim_set_current_win()`, or, when the `mouse` field is set to true,
--- by mouse events. See `focusable`.
--- - footer: (optional) Footer in window border, string or list.
--- List should consist of `[text, highlight]` tuples.
--- If string, or a tuple lacks a highlight, the default highlight group is `FloatFooter`.
--- - footer_pos: Footer position. Must be set with `footer` option.
--- Value can be one of "left", "center", or "right".
--- Default is `"left"`.
--- - height: Window height (in character cells). Minimum of 1.
--- - hide: If true the floating window will be hidden and the cursor will be invisible when
--- focused on it.
--- - vertical: Split vertically `:vertical`.
--- - mouse: Specify how this window interacts with mouse events.
--- Defaults to `focusable` value.
--- - If false, mouse events pass through this window.
--- - If true, mouse events interact with this window normally.
--- - noautocmd: Block all autocommands for the duration of the call. Cannot be changed by
--- `nvim_win_set_config()`.
--- - relative: Sets the window layout to "floating", placed at (row,col)
--- coordinates relative to:
--- - "cursor" Cursor position in current window.
--- - "editor" The global editor grid.
--- - "laststatus" 'laststatus' if present, or last row.
--- - "mouse" Mouse position.
--- - "tabline" Tabline if present, or first row.
--- - "win" Window given by the `win` field, or current window.
--- - row: Row position in units of "screen cell height", may be fractional.
--- - split: Split direction: "left", "right", "above", "below".
--- - style: (optional) Configure the appearance of the window. Currently
--- only supports one value:
--- - "minimal" Nvim will display the window with many UI options
--- disabled. This is useful when displaying a temporary
--- float where the text should not be edited. Disables
--- 'number', 'relativenumber', 'cursorline', 'cursorcolumn',
--- 'foldcolumn', 'spell' and 'list' options. 'signcolumn'
--- is changed to `auto` and 'colorcolumn' is cleared.
--- 'statuscolumn' is changed to empty. The end-of-buffer
--- region is hidden by setting `eob` flag of
--- 'fillchars' to a space char, and clearing the
--- `hl-EndOfBuffer` region in 'winhighlight'.
--- - title: (optional) Title in window border, string or list.
--- List should consist of `[text, highlight]` tuples.
--- If string, or a tuple lacks a highlight, the default highlight group is `FloatTitle`.
--- - title_pos: Title position. Must be set with `title` option.
--- Value can be one of "left", "center", or "right".
--- Default is `"left"`.
--- - vertical: Split vertically `:vertical`.
--- - width: Window width (in character cells). Minimum of 1.
--- - win: `window-ID` window to split, or relative window when creating a
--- float (relative="win").
--- - zindex: Stacking order. floats with higher `zindex` go on top on
--- floats with lower indices. Must be larger than zero. The
--- following screen elements have hard-coded z-indices:
--- - 100: insert completion popupmenu
--- - 200: message scrollback
--- - 250: cmdline completion popupmenu (when wildoptions+=pum)
--- The default value for floats are 50. In general, values below 100 are
--- recommended, unless there is a good reason to overshadow builtin
--- elements.
--- - _cmdline_offset: (EXPERIMENTAL) When provided, anchor the `cmdline-completion`
--- popupmenu to this window, with an offset in screen cell width.
--- @return integer # |window-ID|, or 0 on error