Skip to content

Commit 1a09f11

Browse files
girishjichrisbra
authored andcommitted
patch 9.1.1856: cannot style popup window (border, shadow, etc)
Problem: cannot style popup window (border, shadow, etc) Solution: Extend the 'completepopup' option with additional properties (Girish Palya) This patch extends the 'completepopup' option with additional settings to allow more configuration of info popup window. New values: ``` - close "on" (default) or "off" - resize "on" (default) or "off" - borderchars specify eight characters (separated by semicolons) to draw the popup border: top, right, bottom, left, topleft, topright, botright, botleft. - borderhighlight highlight group for the popup border characters - shadow pum shadow ``` closes: #18487 Signed-off-by: Girish Palya <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent e15cd0f commit 1a09f11

12 files changed

Lines changed: 324 additions & 59 deletions

File tree

runtime/doc/insert.txt

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*insert.txt* For Vim version 9.1. Last change: 2025 Oct 12
1+
*insert.txt* For Vim version 9.1. Last change: 2025 Oct 14
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1287,26 +1287,9 @@ remove existing text in the preview window. The size of the preview window is
12871287
three lines, but 'previewheight' is used when it has a value of 1 or 2.
12881288

12891289
*complete-popup*
1290-
When "popup" is in 'completeopt' a popup window is used to display the "info".
1291-
Then the 'completepopup' option specifies the properties of the popup. This
1292-
is used when the info popup is created. The option is a comma-separated list
1293-
of values:
1294-
height maximum height of the popup
1295-
width maximum width of the popup
1296-
highlight highlight group of the popup (default is PmenuSel)
1297-
align "item" (default) or "menu"
1298-
border "on" (default) or "off"
1299-
Example: >
1300-
:set completepopup=height:10,width:60,highlight:InfoPopup
1301-
1302-
When `"align"` is set to `"item"`, the popup is positioned near the selected
1303-
item, and moves as the selection changes.
1304-
When set to `"menu"`, the popup aligns with the top of the menu (if the menu
1305-
appears below the text), or with the bottom (if the menu appears above).
1306-
1307-
If the 'mouse' is enabled, a close button and resize handle will appear on the
1308-
popup border.
1309-
1290+
When "popup" is included in 'completeopt', a popup window is used to display
1291+
the completion "info" text. The appearance and behavior of this popup are
1292+
controlled by the 'completepopup' option when the popup is created.
13101293
After creation, the info popup can be located with |popup_findinfo()| and
13111294
modified using |popup_setoptions()|.
13121295

runtime/doc/options.txt

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 9.1. Last change: 2025 Oct 12
1+
*options.txt* For Vim version 9.1. Last change: 2025 Oct 14
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2339,12 +2339,50 @@ A jump table for the options with a short description can be found at |Q_op|.
23392339
global
23402340
{not available when compiled without the |+textprop|
23412341
or |+quickfix| feature}
2342-
When 'completeopt' contains "popup" then this option is used for the
2342+
When 'completeopt' contains "popup", this option specifies the
23432343
properties of the info popup when it is created. If an info popup
23442344
window already exists it is closed, so that the option value is
23452345
applied when it is created again.
2346-
You can also use |popup_findinfo()| and then set properties for an
2347-
existing info popup with |popup_setoptions()|. See |complete-popup|.
2346+
2347+
The option is a comma-separated list of values:
2348+
align "item" (default) or "menu"
2349+
border border style:
2350+
"single" thin box-drawing characters
2351+
"double" double-line
2352+
"round" rounded corners
2353+
"ascii" ASCII characters (-, |, +)
2354+
"custom:X;X;X;X;X;X;X;X"
2355+
eight characters separated by
2356+
semicolons, in the order: top,
2357+
right, bottom, left, topleft,
2358+
topright, botright, botleft
2359+
"on" same as "double" when
2360+
'encoding' is "utf-8" and
2361+
'ambiwidth' is "single", else
2362+
"ascii" (default)
2363+
"off" no border
2364+
borderhighlight highlight group for the popup border characters
2365+
close show close button: "on" (default) or "off"
2366+
height maximum height of the popup
2367+
highlight popup highlight group (default: PmenuSel)
2368+
resize show resize handle: "on" (default) or "off"
2369+
shadow "off" (default) or "on" using |hl-PmenuShadow|
2370+
width maximum width of the popup
2371+
2372+
Example: >
2373+
:set completepopup=height:10,border:single,highlight:InfoPopup
2374+
:set completepopup=width:60,border:custom:─;│;─;│;┌;┐;┘;└
2375+
<
2376+
When "align" is set to "item", the popup is positioned near the
2377+
selected item and moves as the selection changes.
2378+
When set to "menu", the popup aligns with the top of the menu (if the
2379+
menu appears below the text) or with the bottom (if it appears above).
2380+
2381+
The close button and resize handle are shown on the popup border only
2382+
when 'mouse' is enabled.
2383+
2384+
After creation, the info popup can be located with |popup_findinfo()|
2385+
and modified using |popup_setoptions()|. See also: |complete-popup|.
23482386

23492387
*'completeslash'* *'csl'*
23502388
'completeslash' 'csl' string (default: "")

runtime/doc/version9.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41717,6 +41717,7 @@ Options: ~
4171741717
to ">" by default, indicating text that extends beyond the window width.
4171841718
- 'guioptions': New value |'go-C'| to style the title/caption bar on Windows 11
4171941719
(see also the below platform specific change).
41720+
- 'completepopup': Add more values to style popup windows.
4172041721

4172141722
Ex commands: ~
4172241723
- allow to specify a priority when defining a new sign |:sign-define|

src/optiondefs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ static struct vimoption options[] =
711711
SCTX_INIT},
712712
{"completepopup", "cpp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_COLON,
713713
#if defined(FEAT_PROP_POPUP) && defined(FEAT_QUICKFIX)
714-
(char_u *)&p_cpp, PV_NONE, did_set_completepopup, expand_set_popupoption,
714+
(char_u *)&p_cpp, PV_NONE, did_set_completepopup, expand_set_completepopup,
715715
{(char_u *)"", (char_u *)0L}
716716
#else
717717
(char_u *)NULL, PV_NONE, NULL, NULL,
@@ -1991,7 +1991,7 @@ static struct vimoption options[] =
19911991
{(char_u *)12L, (char_u *)0L} SCTX_INIT},
19921992
{"previewpopup", "pvp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_COLON,
19931993
#ifdef FEAT_PROP_POPUP
1994-
(char_u *)&p_pvp, PV_NONE, did_set_previewpopup, expand_set_popupoption,
1994+
(char_u *)&p_pvp, PV_NONE, did_set_previewpopup, expand_set_previewpopup,
19951995
{(char_u *)"", (char_u *)0L}
19961996
#else
19971997
(char_u *)NULL, PV_NONE, NULL, NULL,

src/optionstr.c

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ static char *(p_fdo_values[]) = {"all", "block", "hor", "mark", "percent",
7070
static char *(p_kpc_protocol_values[]) = {"none", "mok2", "kitty", NULL};
7171
#ifdef FEAT_PROP_POPUP
7272
// Note: Keep this in sync with parse_popup_option()
73-
static char *(p_popup_option_values[]) = { "align:", "border:", "height:",
74-
"highlight:", "shadow:", "width:", NULL};
75-
static char *(p_popup_option_border_values[]) = {"on", "off", NULL};
73+
static char *(p_popup_cpp_option_values[]) = {"align:", "border:",
74+
"borderhighlight:", "close:", "height:", "highlight:", "resize:",
75+
"shadow:", "width:", NULL};
76+
static char *(p_popup_pvp_option_values[]) = {"height:", "highlight:",
77+
"width:", NULL};
78+
static char *(p_popup_option_on_off_values[]) = {"on", "off", NULL};
79+
static char *(p_popup_cpp_border_values[]) = {"single", "double", "round",
80+
"ascii", "on", "off", "custom:", NULL};
7681
static char *(p_popup_option_align_values[]) = {"item", "menu", NULL};
7782
#endif
7883
#if defined(FEAT_SPELL)
@@ -3408,22 +3413,44 @@ did_set_previewpopup(optset_T *args UNUSED)
34083413
return NULL;
34093414
}
34103415

3411-
int
3412-
expand_set_popupoption(optexpand_T *args, int *numMatches, char_u ***matches)
3416+
static int
3417+
expand_set_popupoption(optexpand_T *args, int *numMatches, char_u ***matches,
3418+
int previewpopup)
34133419
{
34143420
expand_T *xp = args->oe_xp;
34153421

34163422
if (xp->xp_pattern > args->oe_set_arg && *(xp->xp_pattern-1) == ':')
34173423
{
34183424
// Within "highlight:"/"border:"/"align:", we have a subgroup of possible options.
34193425
int border_len = (int)STRLEN("border:");
3420-
if (xp->xp_pattern - args->oe_set_arg >= border_len &&
3421-
STRNCMP(xp->xp_pattern - border_len, "border:", border_len) == 0)
3426+
int close_len = (int)STRLEN("close:");
3427+
int resize_len = (int)STRLEN("resize:");
3428+
int shadow_len = (int)STRLEN("shadow:");
3429+
int is_border = xp->xp_pattern - args->oe_set_arg >= border_len &&
3430+
STRNCMP(xp->xp_pattern - border_len, "border:", border_len) == 0;
3431+
int is_close = xp->xp_pattern - args->oe_set_arg >= close_len &&
3432+
STRNCMP(xp->xp_pattern - close_len, "close:", close) == 0;
3433+
int is_resize = xp->xp_pattern - args->oe_set_arg >= resize_len &&
3434+
STRNCMP(xp->xp_pattern - resize_len, "resize:", resize_len) == 0;
3435+
int is_shadow = xp->xp_pattern - args->oe_set_arg >= shadow_len &&
3436+
STRNCMP(xp->xp_pattern - shadow_len, "shadow:", shadow_len) == 0;
3437+
if (is_close || is_resize || is_shadow)
3438+
{
3439+
return expand_set_opt_string(
3440+
args,
3441+
p_popup_option_on_off_values,
3442+
ARRAY_LENGTH(p_popup_option_on_off_values) - 1,
3443+
numMatches,
3444+
matches);
3445+
}
3446+
if (is_border)
34223447
{
34233448
return expand_set_opt_string(
34243449
args,
3425-
p_popup_option_border_values,
3426-
ARRAY_LENGTH(p_popup_option_border_values) - 1,
3450+
previewpopup ? p_popup_option_on_off_values
3451+
: p_popup_cpp_border_values,
3452+
(previewpopup ? ARRAY_LENGTH(p_popup_option_on_off_values)
3453+
: ARRAY_LENGTH(p_popup_cpp_border_values)) - 1,
34273454
numMatches,
34283455
matches);
34293456
}
@@ -3439,8 +3466,15 @@ expand_set_popupoption(optexpand_T *args, int *numMatches, char_u ***matches)
34393466
matches);
34403467
}
34413468
int highlight_len = (int)STRLEN("highlight:");
3442-
if (xp->xp_pattern - args->oe_set_arg >= highlight_len &&
3443-
STRNCMP(xp->xp_pattern - highlight_len, "highlight:", highlight_len) == 0)
3469+
int borderhighlight_len = (int)STRLEN("borderhighlight:");
3470+
int is_highlight = xp->xp_pattern - args->oe_set_arg >= highlight_len
3471+
&& STRNCMP(xp->xp_pattern - highlight_len, "highlight:",
3472+
highlight_len) == 0;
3473+
int is_borderhighlight
3474+
= xp->xp_pattern - args->oe_set_arg >= borderhighlight_len
3475+
&& STRNCMP(xp->xp_pattern - borderhighlight_len, "highlight:",
3476+
borderhighlight_len) == 0;
3477+
if (is_highlight || is_borderhighlight)
34443478
{
34453479
// Return the list of all highlight names
34463480
return expand_set_opt_generic(
@@ -3454,11 +3488,25 @@ expand_set_popupoption(optexpand_T *args, int *numMatches, char_u ***matches)
34543488

34553489
return expand_set_opt_string(
34563490
args,
3457-
p_popup_option_values,
3458-
ARRAY_LENGTH(p_popup_option_values) - 1,
3491+
previewpopup ? p_popup_pvp_option_values
3492+
: p_popup_cpp_option_values,
3493+
previewpopup ? ARRAY_LENGTH(p_popup_pvp_option_values) - 1
3494+
: ARRAY_LENGTH(p_popup_cpp_option_values) - 1,
34593495
numMatches,
34603496
matches);
34613497
}
3498+
3499+
int
3500+
expand_set_previewpopup(optexpand_T *args, int *numMatches, char_u ***matches)
3501+
{
3502+
return expand_set_popupoption(args, numMatches, matches, TRUE);
3503+
}
3504+
3505+
int
3506+
expand_set_completepopup(optexpand_T *args, int *numMatches, char_u ***matches)
3507+
{
3508+
return expand_set_popupoption(args, numMatches, matches, FALSE);
3509+
}
34623510
#endif
34633511

34643512
#if defined(FEAT_POSTSCRIPT)

0 commit comments

Comments
 (0)