mirror of
https://github.com/neovim/neovim.git
synced 2025-09-23 19:48:32 +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:
@@ -159,17 +159,11 @@
|
||||
/// '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:
|
||||
/// ```
|
||||
/// [ "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" ].
|
||||
/// ```
|
||||
@@ -944,11 +938,11 @@ static void parse_border_style(Object style, WinConfig *fconfig, Error *err)
|
||||
char chars[8][MAX_SCHAR_SIZE];
|
||||
bool shadow_color;
|
||||
} defaults[] = {
|
||||
{ "double", { "╔", "═", "╗", "║", "╝", "═", "╚", "║" }, false },
|
||||
{ "single", { "┌", "─", "┐", "│", "┘", "─", "└", "│" }, false },
|
||||
{ "shadow", { "", "", " ", " ", " ", " ", " ", "" }, true },
|
||||
{ "rounded", { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, false },
|
||||
{ "solid", { " ", " ", " ", " ", " ", " ", " ", " " }, false },
|
||||
{ opt_winborder_values[1], { "╔", "═", "╗", "║", "╝", "═", "╚", "║" }, false },
|
||||
{ opt_winborder_values[2], { "┌", "─", "┐", "│", "┘", "─", "└", "│" }, false },
|
||||
{ opt_winborder_values[3], { "", "", " ", " ", " ", " ", " ", "" }, true },
|
||||
{ opt_winborder_values[4], { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, false },
|
||||
{ opt_winborder_values[5], { " ", " ", " ", " ", " ", " ", " ", " " }, false },
|
||||
{ NULL, { { NUL } }, false },
|
||||
};
|
||||
|
||||
@@ -1279,12 +1273,13 @@ static bool parse_win_config(win_T *wp, Dict(win_config) *config, WinConfig *fco
|
||||
}
|
||||
}
|
||||
|
||||
if (HAS_KEY_X(config, border)) {
|
||||
if (HAS_KEY_X(config, border) || *p_winbd != NUL) {
|
||||
if (is_split) {
|
||||
api_set_error(err, kErrorTypeValidation, "non-float cannot have 'border'");
|
||||
goto fail;
|
||||
}
|
||||
parse_border_style(config->border, fconfig, err);
|
||||
Object style = config->border.type != kObjectTypeNil ? config->border : CSTR_AS_OBJ(p_winbd);
|
||||
parse_border_style(style, fconfig, err);
|
||||
if (ERROR_SET(err)) {
|
||||
goto fail;
|
||||
}
|
||||
|
@@ -566,6 +566,7 @@ EXTERN OptInt p_wcm; ///< 'wildcharm'
|
||||
EXTERN int p_wic; ///< 'wildignorecase'
|
||||
EXTERN char *p_wim; ///< 'wildmode'
|
||||
EXTERN int p_wmnu; ///< 'wildmenu'
|
||||
EXTERN char *p_winbd; ///< 'winborder'
|
||||
EXTERN OptInt p_wh; ///< 'winheight'
|
||||
EXTERN OptInt p_wmh; ///< 'winminheight'
|
||||
EXTERN OptInt p_wmw; ///< 'winminwidth'
|
||||
|
@@ -10188,6 +10188,26 @@ local options = {
|
||||
short_desc = N_('Controls transparency level for floating windows'),
|
||||
type = 'number',
|
||||
},
|
||||
{
|
||||
defaults = { if_true = '' },
|
||||
cb = 'did_set_winborder',
|
||||
values = { '', 'double', 'single', 'shadow', 'rounded', 'solid', 'none' },
|
||||
desc = [=[
|
||||
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.
|
||||
]=],
|
||||
full_name = 'winborder',
|
||||
scope = { 'global' },
|
||||
short_desc = N_('border of floating window'),
|
||||
type = 'string',
|
||||
varname = 'p_winbd',
|
||||
},
|
||||
{
|
||||
abbreviation = 'wi',
|
||||
cb = 'did_set_window',
|
||||
|
@@ -2005,6 +2005,15 @@ const char *did_set_winhighlight(optset_T *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/// The 'winborder' option is changed.
|
||||
const char *did_set_winborder(optset_T *args)
|
||||
{
|
||||
if (opt_strings_flags(p_winbd, opt_winborder_values, NULL, true) != OK) {
|
||||
return e_invarg;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int expand_set_winhighlight(optexpand_T *args, int *numMatches, char ***matches)
|
||||
{
|
||||
return expand_set_opt_generic(args, get_highlight_name, numMatches, matches);
|
||||
|
Reference in New Issue
Block a user