mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +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:
@@ -3493,28 +3493,20 @@ nvim_open_win({buffer}, {enter}, {config}) *nvim_open_win()*
|
||||
`eob` flag of 'fillchars' to a space char, and clearing
|
||||
the |hl-EndOfBuffer| region in 'winhighlight'.
|
||||
• border: Style of (optional) window border. This can either
|
||||
be a string or an array. The string values are
|
||||
• "none": No border (default).
|
||||
• "single": A single line box.
|
||||
• "double": A double line box.
|
||||
• "rounded": Like "single", but with rounded corners
|
||||
("╭" etc.).
|
||||
• "solid": Adds padding by a single whitespace cell.
|
||||
• "shadow": A drop shadow effect by blending with the
|
||||
background.
|
||||
• If it is an array, it should have a length of eight or
|
||||
any divisor of eight. The array will specify the eight
|
||||
chars building up the border in a clockwise fashion
|
||||
starting with the top-left corner. As an example, the
|
||||
double box style could be specified as: >
|
||||
[ "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" ].
|
||||
be a string or an array. The string values are the same as
|
||||
those described in 'winborder'. If it is an array, it
|
||||
should have a length of eight or any divisor of eight. The
|
||||
array will specify the eight chars building up the border
|
||||
in a clockwise fashion starting with the top-left corner.
|
||||
As an example, the double box style could be specified as: >
|
||||
[ "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" ].
|
||||
<
|
||||
If the number of chars are less than eight, they will be
|
||||
repeated. Thus an ASCII border could be specified as >
|
||||
[ "/", "-", \"\\\\\", "|" ],
|
||||
If the number of chars are less than eight, they will be
|
||||
repeated. Thus an ASCII border could be specified as >
|
||||
[ "/", "-", \"\\\\\", "|" ],
|
||||
<
|
||||
or all chars the same as >
|
||||
[ "x" ].
|
||||
or all chars the same as >
|
||||
[ "x" ].
|
||||
<
|
||||
An empty string can be used to turn off a specific border,
|
||||
for instance, >
|
||||
|
||||
@@ -348,6 +348,7 @@ OPTIONS
|
||||
• 'messagesopt' configures |:messages| and |hit-enter| prompt.
|
||||
• 'tabclose' controls which tab page to focus when closing a tab page.
|
||||
• 'eventignorewin' to persistently ignore events in a window.
|
||||
• 'winborder' sets the default border for |floating-windows|
|
||||
|
||||
PERFORMANCE
|
||||
|
||||
|
||||
@@ -7150,6 +7150,18 @@ A jump table for the options with a short description can be found at |Q_op|.
|
||||
|
||||
UI-dependent. Works best with RGB colors. 'termguicolors'
|
||||
|
||||
*'winborder'*
|
||||
'winborder' string (default "")
|
||||
global
|
||||
Defines the default border style of floating windows. The default value
|
||||
is empty, which is equivalent to "none". Valid values include:
|
||||
- "none": No border.
|
||||
- "single": A single line box.
|
||||
- "double": A double line box.
|
||||
- "rounded": Like "single", but with rounded corners ("╭" etc.).
|
||||
- "solid": Adds padding by a single whitespace cell.
|
||||
- "shadow": A drop shadow effect by blending with the background.
|
||||
|
||||
*'window'* *'wi'*
|
||||
'window' 'wi' number (default screen height - 1)
|
||||
global
|
||||
|
||||
16
runtime/lua/vim/_meta/api.lua
generated
16
runtime/lua/vim/_meta/api.lua
generated
@@ -1797,17 +1797,11 @@ function vim.api.nvim_open_term(buffer, opts) end
|
||||
--- 'fillchars' to a space char, and clearing the
|
||||
--- `hl-EndOfBuffer` region in 'winhighlight'.
|
||||
--- - border: Style of (optional) window border. This can either be a string
|
||||
--- or an array. The string values are
|
||||
--- - "none": No border (default).
|
||||
--- - "single": A single line box.
|
||||
--- - "double": A double line box.
|
||||
--- - "rounded": Like "single", but with rounded corners ("╭" etc.).
|
||||
--- - "solid": Adds padding by a single whitespace cell.
|
||||
--- - "shadow": A drop shadow effect by blending with the background.
|
||||
--- - If it is an array, it should have a length of eight or any divisor of
|
||||
--- eight. The array will specify the eight chars building up the border
|
||||
--- in a clockwise fashion starting with the top-left corner. As an
|
||||
--- example, the double box style could be specified as:
|
||||
--- or an array. The string values are the same as those described in 'winborder'.
|
||||
--- If it is an array, it should have a length of eight or any divisor of
|
||||
--- eight. The array will specify the eight chars building up the border
|
||||
--- in a clockwise fashion starting with the top-left corner. As an
|
||||
--- example, the double box style could be specified as:
|
||||
--- ```
|
||||
--- [ "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" ].
|
||||
--- ```
|
||||
|
||||
13
runtime/lua/vim/_meta/options.lua
generated
13
runtime/lua/vim/_meta/options.lua
generated
@@ -7832,6 +7832,19 @@ vim.o.winbl = vim.o.winblend
|
||||
vim.wo.winblend = vim.o.winblend
|
||||
vim.wo.winbl = vim.wo.winblend
|
||||
|
||||
--- Defines the default border style of floating windows. The default value
|
||||
--- is empty, which is equivalent to "none". Valid values include:
|
||||
--- - "none": No border.
|
||||
--- - "single": A single line box.
|
||||
--- - "double": A double line box.
|
||||
--- - "rounded": Like "single", but with rounded corners ("╭" etc.).
|
||||
--- - "solid": Adds padding by a single whitespace cell.
|
||||
--- - "shadow": A drop shadow effect by blending with the background.
|
||||
---
|
||||
--- @type ''|'double'|'single'|'shadow'|'rounded'|'solid'|'none'
|
||||
vim.o.winborder = ""
|
||||
vim.go.winborder = vim.o.winborder
|
||||
|
||||
--- Window height used for `CTRL-F` and `CTRL-B` when there is only one
|
||||
--- window and the value is smaller than 'lines' minus one. The screen
|
||||
--- will scroll 'window' minus two lines, with a minimum of one.
|
||||
|
||||
@@ -6,17 +6,6 @@ local uv = vim.uv
|
||||
|
||||
local M = {}
|
||||
|
||||
local default_border = {
|
||||
{ '', 'NormalFloat' },
|
||||
{ '', 'NormalFloat' },
|
||||
{ '', 'NormalFloat' },
|
||||
{ ' ', 'NormalFloat' },
|
||||
{ '', 'NormalFloat' },
|
||||
{ '', 'NormalFloat' },
|
||||
{ '', 'NormalFloat' },
|
||||
{ ' ', 'NormalFloat' },
|
||||
}
|
||||
|
||||
--- @param border string|(string|[string,string])[]
|
||||
local function border_error(border)
|
||||
error(
|
||||
@@ -43,7 +32,11 @@ local border_size = {
|
||||
--- @return integer height
|
||||
--- @return integer width
|
||||
local function get_border_size(opts)
|
||||
local border = opts and opts.border or default_border
|
||||
local border = opts and opts.border or vim.o.winborder
|
||||
|
||||
if border == '' then
|
||||
border = 'none'
|
||||
end
|
||||
|
||||
if type(border) == 'string' then
|
||||
if not border_size[border] then
|
||||
@@ -884,7 +877,7 @@ function M.make_floating_popup_options(width, height, opts)
|
||||
or 'cursor',
|
||||
style = 'minimal',
|
||||
width = width,
|
||||
border = opts.border or default_border,
|
||||
border = opts.border,
|
||||
zindex = opts.zindex or (api.nvim_win_get_config(0).zindex or 49) + 1,
|
||||
title = title,
|
||||
title_pos = title_pos,
|
||||
|
||||
Reference in New Issue
Block a user