Skip to content

Commit cb5ff34

Browse files
committed
patch 8.1.1718: popup menu highlighting does not look good
Problem: Popup menu highlighting does not look good. Solution: Highlight the whole window line. Fix that sign line HL is not displayed in a window with a background color.
1 parent f914a33 commit cb5ff34

14 files changed

Lines changed: 75 additions & 27 deletions

src/popupwin.c

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,22 @@ popup_show_curline(win_T *wp)
451451
wp->w_topline = wp->w_cursor.lnum;
452452
else if (wp->w_cursor.lnum >= wp->w_botline)
453453
wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1;
454+
455+
// Don't use "firstline" now.
456+
wp->w_firstline = 0;
457+
}
458+
459+
/*
460+
* Get the sign group name for window "wp".
461+
* Returns a pointer to a static buffer, overwritten on the next call.
462+
*/
463+
static char_u *
464+
popup_get_sign_name(win_T *wp)
465+
{
466+
static char buf[30];
467+
468+
vim_snprintf(buf, sizeof(buf), "popup-%d", wp->w_id);
469+
return (char_u *)buf;
454470
}
455471

456472
/*
@@ -460,20 +476,31 @@ popup_show_curline(win_T *wp)
460476
static void
461477
popup_highlight_curline(win_T *wp)
462478
{
463-
int id;
464-
char buf[100];
479+
int sign_id = 0;
480+
char_u *sign_name = popup_get_sign_name(wp);
465481

466-
match_delete(wp, 1, FALSE);
482+
buf_delete_signs(wp->w_buffer, (char_u *)"popupmenu");
467483

468484
if ((wp->w_popup_flags & POPF_CURSORLINE) != 0)
469485
{
470486
popup_show_curline(wp);
471487

472-
id = syn_name2id((char_u *)"PopupSelected");
473-
vim_snprintf(buf, sizeof(buf), "\\%%%dl.*", (int)wp->w_cursor.lnum);
474-
match_add(wp, (char_u *)(id == 0 ? "PmenuSel" : "PopupSelected"),
475-
(char_u *)buf, 10, 1, NULL, NULL);
488+
if (!sign_exists_by_name(sign_name))
489+
{
490+
char *linehl = "PopupSelected";
491+
492+
if (syn_name2id((char_u *)linehl) == 0)
493+
linehl = "PmenuSel";
494+
sign_define_by_name(sign_name, NULL,
495+
(char_u *)linehl, NULL, NULL);
496+
}
497+
498+
sign_place(&sign_id, (char_u *)"popupmenu", sign_name,
499+
wp->w_buffer, wp->w_cursor.lnum, SIGN_DEF_PRIO);
500+
redraw_win_later(wp, NOT_VALID);
476501
}
502+
else
503+
sign_undefine_by_name(sign_name, FALSE);
477504
}
478505

479506
/*
@@ -545,6 +572,8 @@ apply_general_options(win_T *wp, dict_T *dict)
545572
set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
546573
str, OPT_FREE|OPT_LOCAL, 0);
547574

575+
set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1,
576+
(char_u *)"no", OPT_FREE|OPT_LOCAL, 0);
548577
set_padding_border(dict, wp->w_popup_padding, "padding", 999);
549578
set_padding_border(dict, wp->w_popup_border, "border", 1);
550579

@@ -1219,7 +1248,7 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
12191248

12201249
if (argvars != NULL)
12211250
{
1222-
// Check arguments look OK.
1251+
// Check that arguments look OK.
12231252
if (argvars[0].v_type == VAR_NUMBER)
12241253
{
12251254
buf = buflist_findnr( argvars[0].vval.v_number);
@@ -1671,7 +1700,7 @@ f_popup_filter_menu(typval_T *argvars, typval_T *rettv)
16711700
++wp->w_cursor.lnum;
16721701
if (old_lnum != wp->w_cursor.lnum)
16731702
{
1674-
popup_highlight_curline(wp);
1703+
// caller will call popup_highlight_curline()
16751704
return;
16761705
}
16771706

@@ -1849,10 +1878,12 @@ f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED)
18491878
static void
18501879
popup_free(win_T *wp)
18511880
{
1881+
sign_undefine_by_name(popup_get_sign_name(wp), FALSE);
18521882
wp->w_buffer->b_locked = FALSE;
18531883
if (wp->w_winrow + wp->w_height >= cmdline_row)
18541884
clear_cmdline = TRUE;
18551885
win_free_popup(wp);
1886+
18561887
redraw_all_later(NOT_VALID);
18571888
popup_mask_refresh = TRUE;
18581889
}
@@ -2161,7 +2192,8 @@ f_popup_getoptions(typval_T *argvars, typval_T *rettv)
21612192
dict_add_string(dict, "title", wp->w_popup_title);
21622193
dict_add_number(dict, "wrap", wp->w_p_wrap);
21632194
dict_add_number(dict, "drag", wp->w_popup_drag);
2164-
dict_add_number(dict, "cursorline", (wp->w_popup_flags & POPF_CURSORLINE) != 0);
2195+
dict_add_number(dict, "cursorline",
2196+
(wp->w_popup_flags & POPF_CURSORLINE) != 0);
21652197
dict_add_string(dict, "highlight", wp->w_p_wcr);
21662198
if (wp->w_scrollbar_highlight != NULL)
21672199
dict_add_string(dict, "scrollbarhighlight",
@@ -2321,7 +2353,7 @@ invoke_popup_filter(win_T *wp, int c)
23212353
// NOTE: The callback might close the popup, thus make "wp" invalid.
23222354
call_callback(&wp->w_filter_cb, -1,
23232355
&rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL);
2324-
if (old_lnum != wp->w_cursor.lnum)
2356+
if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
23252357
popup_highlight_curline(wp);
23262358

23272359
res = tv_get_number(&rettv);

src/proto/sign.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ int buf_signcount(buf_T *buf, linenr_T lnum);
99
void buf_delete_signs(buf_T *buf, char_u *group);
1010
void sign_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after);
1111
int sign_define_by_name(char_u *name, char_u *icon, char_u *linehl, char_u *text, char_u *texthl);
12-
int sign_undefine_by_name(char_u *name);
12+
int sign_exists_by_name(char_u *name);
13+
int sign_undefine_by_name(char_u *name, int give_error);
14+
int sign_place(int *sign_id, char_u *sign_group, char_u *sign_name, buf_T *buf, linenr_T lnum, int prio);
1315
void ex_sign(exarg_T *eap);
1416
void get_buffer_signs(buf_T *buf, list_T *l);
1517
void sign_gui_started(void);

src/screen.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5366,6 +5366,8 @@ win_line(
53665366
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
53675367
char_attr = hl_combine_attr(char_attr,
53685368
HL_ATTR(HLF_CUL));
5369+
else if (line_attr)
5370+
char_attr = hl_combine_attr(char_attr, line_attr);
53695371
}
53705372
# endif
53715373
}

src/sign.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,19 +1024,29 @@ sign_define_by_name(
10241024
return OK;
10251025
}
10261026

1027+
/*
1028+
* Return TRUE if sign "name" exists.
1029+
*/
1030+
int
1031+
sign_exists_by_name(char_u *name)
1032+
{
1033+
return sign_find(name, NULL) != NULL;
1034+
}
1035+
10271036
/*
10281037
* Free the sign specified by 'name'.
10291038
*/
10301039
int
1031-
sign_undefine_by_name(char_u *name)
1040+
sign_undefine_by_name(char_u *name, int give_error)
10321041
{
10331042
sign_T *sp_prev;
10341043
sign_T *sp;
10351044

10361045
sp = sign_find(name, &sp_prev);
10371046
if (sp == NULL)
10381047
{
1039-
semsg(_("E155: Unknown sign: %s"), name);
1048+
if (give_error)
1049+
semsg(_("E155: Unknown sign: %s"), name);
10401050
return FAIL;
10411051
}
10421052
sign_undefine(sp, sp_prev);
@@ -1076,7 +1086,7 @@ may_force_numberwidth_recompute(buf_T *buf, int unplace)
10761086
/*
10771087
* Place a sign at the specified file location or update a sign.
10781088
*/
1079-
static int
1089+
int
10801090
sign_place(
10811091
int *sign_id,
10821092
char_u *sign_group,
@@ -1591,7 +1601,7 @@ ex_sign(exarg_T *eap)
15911601
sign_list_by_name(name);
15921602
else
15931603
// ":sign undefine {name}"
1594-
sign_undefine_by_name(name);
1604+
sign_undefine_by_name(name, TRUE);
15951605

15961606
vim_free(name);
15971607
return;
@@ -2512,7 +2522,7 @@ sign_undefine_multiple(list_T *l, list_T *retlist)
25122522
{
25132523
retval = -1;
25142524
name = tv_get_string_chk(&li->li_tv);
2515-
if (name != NULL && (sign_undefine_by_name(name) == OK))
2525+
if (name != NULL && (sign_undefine_by_name(name, TRUE) == OK))
25162526
retval = 0;
25172527
list_append_number(retlist, retval);
25182528
}
@@ -2551,7 +2561,7 @@ f_sign_undefine(typval_T *argvars, typval_T *rettv)
25512561
if (name == NULL)
25522562
return;
25532563

2554-
if (sign_undefine_by_name(name) == OK)
2564+
if (sign_undefine_by_name(name, TRUE) == OK)
25552565
rettv->vval.v_number = 0;
25562566
}
25572567
}

src/testdir/dumps/Test_popupwin_menu_01.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
>1+0&#ffffff0| @73
22
|2| @73
33
|3| @20|╔+0#0000001#ffd7ff255| |m|a|k|e| |a| |c|h|o|i|c|e| |f|r|o|m| |t|h|e| |l|i|s|t| |╗| +0#0000000#ffffff0@21
4-
|4| @20|║+0#0000001#ffd7ff255| |o+0#0000000#5fd7ff255|n|e| +0#0000001#ffd7ff255@24|║| +0#0000000#ffffff0@21
4+
|4| @20|║+0#0000001#ffd7ff255| |o+0#0000000#5fd7ff255|n|e| +0#0000001&@23| +0&#ffd7ff255|║| +0#0000000#ffffff0@21
55
|5| @20|║+0#0000001#ffd7ff255| |t|w|o| @24|║| +0#0000000#ffffff0@21
66
|6| @20|║+0#0000001#ffd7ff255| |a|n|o|t|h|e|r| @20|║| +0#0000000#ffffff0@21
77
|7| @20|╚+0#0000001#ffd7ff255|═@28|╝| +0#0000000#ffffff0@21

src/testdir/dumps/Test_popupwin_menu_02.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
|3| @20|╔+0#0000001#ffd7ff255| |m|a|k|e| |a| |c|h|o|i|c|e| |f|r|o|m| |t|h|e| |l|i|s|t| |╗| +0#0000000#ffffff0@21
44
|4| @20|║+0#0000001#ffd7ff255| |o|n|e| @24|║| +0#0000000#ffffff0@21
55
|5| @20|║+0#0000001#ffd7ff255| |t|w|o| @24|║| +0#0000000#ffffff0@21
6-
|6| @20|║+0#0000001#ffd7ff255| |a+0#0000000#5fd7ff255|n|o|t|h|e|r| +0#0000001#ffd7ff255@20|║| +0#0000000#ffffff0@21
6+
|6| @20|║+0#0000001#ffd7ff255| |a+0#0000000#5fd7ff255|n|o|t|h|e|r| +0#0000001&@19| +0&#ffd7ff255|║| +0#0000000#ffffff0@21
77
|7| @20|╚+0#0000001#ffd7ff255|═@28|╝| +0#0000000#ffffff0@21
88
|8| @73
99
|9| @73

src/testdir/dumps/Test_popupwin_menu_04.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
>1+0&#ffffff0| @73
22
|2| @73
33
|3| @31|╔+0#0000001#ffd7ff255|═@6|╗| +0#0000000#ffffff0@32
4-
|4| @31|║+0#0000001#ffd7ff255| |o+0#0000000#40ff4011|n|e| +0#0000001#ffd7ff255@2|║| +0#0000000#ffffff0@32
4+
|4| @31|║+0#0000001#ffd7ff255| |o+0#0000000#40ff4011|n|e| +0#0000001&@1| +0&#ffd7ff255|║| +0#0000000#ffffff0@32
55
|5| @31|║+0#0000001#ffd7ff255| |t|w|o| @2|║| +0#0000000#ffffff0@32
66
|6| @31|║+0#0000001#ffd7ff255| |t|h|r|e@1| |║| +0#0000000#ffffff0@32
77
|7| @31|╚+0#0000001#ffd7ff255|═@6|╝| +0#0000000#ffffff0@32

src/testdir/dumps/Test_popupwin_menu_scroll_1.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
|2| @73
33
|3| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
44
|4| @29|║+0#0000001#ffd7ff255| |o|n|e| @5| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
5-
|5| @29|║+0#0000001#ffd7ff255| |t+0&#e0e0e08|w|o| +0&#ffd7ff255@5| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
5+
|5| @29|║+0#0000001#ffd7ff255| |t+0&#e0e0e08|w|o| @4| +0&#ffd7ff255| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
66
|6| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
77
|7| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
88
|8| @73

src/testdir/dumps/Test_popupwin_menu_scroll_2.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
|3| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
44
|4| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
55
|5| @29|║+0#0000001#ffd7ff255| |f|o|u|r| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
6-
|6| @29|║+0#0000001#ffd7ff255| |f+0&#e0e0e08|i|v|e| +0&#ffd7ff255@4| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
6+
|6| @29|║+0#0000001#ffd7ff255| |f+0&#e0e0e08|i|v|e| @3| +0&#ffd7ff255| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
77
|7| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
88
|8| @73
99
|9| @73

src/testdir/dumps/Test_popupwin_menu_scroll_3.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
|3| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
44
|4| @29|║+0#0000001#ffd7ff255| |s|e|v|e|n| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
55
|5| @29|║+0#0000001#ffd7ff255| |e|i|g|h|t| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
6-
|6| @29|║+0#0000001#ffd7ff255| |n+0&#e0e0e08|i|n|e| +0&#ffd7ff255@4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
6+
|6| @29|║+0#0000001#ffd7ff255| |n+0&#e0e0e08|i|n|e| @3| +0&#ffd7ff255| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
77
|7| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
88
|8| @73
99
|9| @73

0 commit comments

Comments
 (0)