changeset 17440:a5874fdc8f3a v8.1.1718

patch 8.1.1718: popup menu highlighting does not look good commit https://github.com/vim/vim/commit/cb5ff34c1b8a89fcdb86653ab18d0aa53f665642 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 20 16:51:19 2019 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Sat, 20 Jul 2019 17:00:08 +0200
parents 8be5444ee2cb
children b50d3687f31c
files src/popupwin.c src/proto/sign.pro src/screen.c src/sign.c src/testdir/dumps/Test_popupwin_menu_01.dump src/testdir/dumps/Test_popupwin_menu_02.dump src/testdir/dumps/Test_popupwin_menu_04.dump src/testdir/dumps/Test_popupwin_menu_scroll_1.dump src/testdir/dumps/Test_popupwin_menu_scroll_2.dump src/testdir/dumps/Test_popupwin_menu_scroll_3.dump src/testdir/dumps/Test_popupwin_menu_scroll_4.dump src/testdir/dumps/Test_popupwin_menu_scroll_5.dump src/testdir/dumps/Test_popupwin_menu_scroll_6.dump src/version.c
diffstat 14 files changed, 76 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -451,6 +451,22 @@ popup_show_curline(win_T *wp)
 	wp->w_topline = wp->w_cursor.lnum;
     else if (wp->w_cursor.lnum >= wp->w_botline)
 	wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1;
+
+    // Don't use "firstline" now.
+    wp->w_firstline = 0;
+}
+
+/*
+ * Get the sign group name for window "wp".
+ * Returns a pointer to a static buffer, overwritten on the next call.
+ */
+    static char_u *
+popup_get_sign_name(win_T *wp)
+{
+    static char    buf[30];
+
+    vim_snprintf(buf, sizeof(buf), "popup-%d", wp->w_id);
+    return (char_u *)buf;
 }
 
 /*
@@ -460,20 +476,31 @@ popup_show_curline(win_T *wp)
     static void
 popup_highlight_curline(win_T *wp)
 {
-    int	    id;
-    char    buf[100];
-
-    match_delete(wp, 1, FALSE);
+    int	    sign_id = 0;
+    char_u  *sign_name = popup_get_sign_name(wp);
+
+    buf_delete_signs(wp->w_buffer, (char_u *)"popupmenu");
 
     if ((wp->w_popup_flags & POPF_CURSORLINE) != 0)
     {
 	popup_show_curline(wp);
 
-	id = syn_name2id((char_u *)"PopupSelected");
-	vim_snprintf(buf, sizeof(buf), "\\%%%dl.*", (int)wp->w_cursor.lnum);
-	match_add(wp, (char_u *)(id == 0 ? "PmenuSel" : "PopupSelected"),
-					     (char_u *)buf, 10, 1, NULL, NULL);
+	if (!sign_exists_by_name(sign_name))
+	{
+	    char *linehl = "PopupSelected";
+
+	    if (syn_name2id((char_u *)linehl) == 0)
+		linehl = "PmenuSel";
+	    sign_define_by_name(sign_name, NULL,
+						 (char_u *)linehl, NULL, NULL);
+	}
+
+	sign_place(&sign_id, (char_u *)"popupmenu", sign_name,
+			       wp->w_buffer, wp->w_cursor.lnum, SIGN_DEF_PRIO);
+	redraw_win_later(wp, NOT_VALID);
     }
+    else
+	sign_undefine_by_name(sign_name, FALSE);
 }
 
 /*
@@ -545,6 +572,8 @@ apply_general_options(win_T *wp, dict_T 
 	set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
 						   str, OPT_FREE|OPT_LOCAL, 0);
 
+    set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1,
+					(char_u *)"no", OPT_FREE|OPT_LOCAL, 0);
     set_padding_border(dict, wp->w_popup_padding, "padding", 999);
     set_padding_border(dict, wp->w_popup_border, "border", 1);
 
@@ -1219,7 +1248,7 @@ popup_create(typval_T *argvars, typval_T
 
     if (argvars != NULL)
     {
-	// Check arguments look OK.
+	// Check that arguments look OK.
 	if (argvars[0].v_type == VAR_NUMBER)
 	{
 	    buf = buflist_findnr( argvars[0].vval.v_number);
@@ -1671,7 +1700,7 @@ f_popup_filter_menu(typval_T *argvars, t
 	++wp->w_cursor.lnum;
     if (old_lnum != wp->w_cursor.lnum)
     {
-	popup_highlight_curline(wp);
+	// caller will call popup_highlight_curline()
 	return;
     }
 
@@ -1849,10 +1878,12 @@ f_popup_settext(typval_T *argvars, typva
     static void
 popup_free(win_T *wp)
 {
+    sign_undefine_by_name(popup_get_sign_name(wp), FALSE);
     wp->w_buffer->b_locked = FALSE;
     if (wp->w_winrow + wp->w_height >= cmdline_row)
 	clear_cmdline = TRUE;
     win_free_popup(wp);
+
     redraw_all_later(NOT_VALID);
     popup_mask_refresh = TRUE;
 }
@@ -2161,7 +2192,8 @@ f_popup_getoptions(typval_T *argvars, ty
 	dict_add_string(dict, "title", wp->w_popup_title);
 	dict_add_number(dict, "wrap", wp->w_p_wrap);
 	dict_add_number(dict, "drag", wp->w_popup_drag);
-	dict_add_number(dict, "cursorline", (wp->w_popup_flags & POPF_CURSORLINE) != 0);
+	dict_add_number(dict, "cursorline",
+				   (wp->w_popup_flags & POPF_CURSORLINE) != 0);
 	dict_add_string(dict, "highlight", wp->w_p_wcr);
 	if (wp->w_scrollbar_highlight != NULL)
 	    dict_add_string(dict, "scrollbarhighlight",
@@ -2321,7 +2353,7 @@ invoke_popup_filter(win_T *wp, int c)
     // NOTE: The callback might close the popup, thus make "wp" invalid.
     call_callback(&wp->w_filter_cb, -1,
 			    &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL);
-    if (old_lnum != wp->w_cursor.lnum)
+    if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
 	popup_highlight_curline(wp);
 
     res = tv_get_number(&rettv);
--- a/src/proto/sign.pro
+++ b/src/proto/sign.pro
@@ -9,7 +9,9 @@ int buf_signcount(buf_T *buf, linenr_T l
 void buf_delete_signs(buf_T *buf, char_u *group);
 void sign_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after);
 int sign_define_by_name(char_u *name, char_u *icon, char_u *linehl, char_u *text, char_u *texthl);
-int sign_undefine_by_name(char_u *name);
+int sign_exists_by_name(char_u *name);
+int sign_undefine_by_name(char_u *name, int give_error);
+int sign_place(int *sign_id, char_u *sign_group, char_u *sign_name, buf_T *buf, linenr_T lnum, int prio);
 void ex_sign(exarg_T *eap);
 void get_buffer_signs(buf_T *buf, list_T *l);
 void sign_gui_started(void);
--- a/src/screen.c
+++ b/src/screen.c
@@ -5366,6 +5366,8 @@ win_line(
 			if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
 			    char_attr = hl_combine_attr(char_attr,
 							    HL_ATTR(HLF_CUL));
+			else if (line_attr)
+			    char_attr = hl_combine_attr(char_attr, line_attr);
 		    }
 # endif
 		}
--- a/src/sign.c
+++ b/src/sign.c
@@ -1025,10 +1025,19 @@ sign_define_by_name(
 }
 
 /*
+ * Return TRUE if sign "name" exists.
+ */
+    int
+sign_exists_by_name(char_u *name)
+{
+    return sign_find(name, NULL) != NULL;
+}
+
+/*
  * Free the sign specified by 'name'.
  */
     int
-sign_undefine_by_name(char_u *name)
+sign_undefine_by_name(char_u *name, int give_error)
 {
     sign_T	*sp_prev;
     sign_T	*sp;
@@ -1036,7 +1045,8 @@ sign_undefine_by_name(char_u *name)
     sp = sign_find(name, &sp_prev);
     if (sp == NULL)
     {
-	semsg(_("E155: Unknown sign: %s"), name);
+	if (give_error)
+	    semsg(_("E155: Unknown sign: %s"), name);
 	return FAIL;
     }
     sign_undefine(sp, sp_prev);
@@ -1076,7 +1086,7 @@ may_force_numberwidth_recompute(buf_T *b
 /*
  * Place a sign at the specified file location or update a sign.
  */
-    static int
+    int
 sign_place(
 	int		*sign_id,
 	char_u		*sign_group,
@@ -1591,7 +1601,7 @@ ex_sign(exarg_T *eap)
 		sign_list_by_name(name);
 	    else
 		// ":sign undefine {name}"
-		sign_undefine_by_name(name);
+		sign_undefine_by_name(name, TRUE);
 
 	    vim_free(name);
 	    return;
@@ -2512,7 +2522,7 @@ sign_undefine_multiple(list_T *l, list_T
     {
 	retval = -1;
 	name = tv_get_string_chk(&li->li_tv);
-	if (name != NULL && (sign_undefine_by_name(name) == OK))
+	if (name != NULL && (sign_undefine_by_name(name, TRUE) == OK))
 	    retval = 0;
 	list_append_number(retlist, retval);
     }
@@ -2551,7 +2561,7 @@ f_sign_undefine(typval_T *argvars, typva
 	if (name == NULL)
 	    return;
 
-	if (sign_undefine_by_name(name) == OK)
+	if (sign_undefine_by_name(name, TRUE) == OK)
 	    rettv->vval.v_number = 0;
     }
 }
--- a/src/testdir/dumps/Test_popupwin_menu_01.dump
+++ b/src/testdir/dumps/Test_popupwin_menu_01.dump
@@ -1,7 +1,7 @@
 >1+0&#ffffff0| @73
 |2| @73
 |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| @20|║+0#0000001#ffd7ff255| |o+0#0000000#5fd7ff255|n|e| +0#0000001#ffd7ff255@24|║| +0#0000000#ffffff0@21
+|4| @20|║+0#0000001#ffd7ff255| |o+0#0000000#5fd7ff255|n|e| +0#0000001&@23| +0&#ffd7ff255|║| +0#0000000#ffffff0@21
 |5| @20|║+0#0000001#ffd7ff255| |t|w|o| @24|║| +0#0000000#ffffff0@21
 |6| @20|║+0#0000001#ffd7ff255| |a|n|o|t|h|e|r| @20|║| +0#0000000#ffffff0@21
 |7| @20|╚+0#0000001#ffd7ff255|═@28|╝| +0#0000000#ffffff0@21
--- a/src/testdir/dumps/Test_popupwin_menu_02.dump
+++ b/src/testdir/dumps/Test_popupwin_menu_02.dump
@@ -3,7 +3,7 @@
 |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| @20|║+0#0000001#ffd7ff255| |o|n|e| @24|║| +0#0000000#ffffff0@21
 |5| @20|║+0#0000001#ffd7ff255| |t|w|o| @24|║| +0#0000000#ffffff0@21
-|6| @20|║+0#0000001#ffd7ff255| |a+0#0000000#5fd7ff255|n|o|t|h|e|r| +0#0000001#ffd7ff255@20|║| +0#0000000#ffffff0@21
+|6| @20|║+0#0000001#ffd7ff255| |a+0#0000000#5fd7ff255|n|o|t|h|e|r| +0#0000001&@19| +0&#ffd7ff255|║| +0#0000000#ffffff0@21
 |7| @20|╚+0#0000001#ffd7ff255|═@28|╝| +0#0000000#ffffff0@21
 |8| @73
 |9| @73
--- a/src/testdir/dumps/Test_popupwin_menu_04.dump
+++ b/src/testdir/dumps/Test_popupwin_menu_04.dump
@@ -1,7 +1,7 @@
 >1+0&#ffffff0| @73
 |2| @73
 |3| @31|╔+0#0000001#ffd7ff255|═@6|╗| +0#0000000#ffffff0@32
-|4| @31|║+0#0000001#ffd7ff255| |o+0#0000000#40ff4011|n|e| +0#0000001#ffd7ff255@2|║| +0#0000000#ffffff0@32
+|4| @31|║+0#0000001#ffd7ff255| |o+0#0000000#40ff4011|n|e| +0#0000001&@1| +0&#ffd7ff255|║| +0#0000000#ffffff0@32
 |5| @31|║+0#0000001#ffd7ff255| |t|w|o| @2|║| +0#0000000#ffffff0@32
 |6| @31|║+0#0000001#ffd7ff255| |t|h|r|e@1| |║| +0#0000000#ffffff0@32
 |7| @31|╚+0#0000001#ffd7ff255|═@6|╝| +0#0000000#ffffff0@32
--- a/src/testdir/dumps/Test_popupwin_menu_scroll_1.dump
+++ b/src/testdir/dumps/Test_popupwin_menu_scroll_1.dump
@@ -2,7 +2,7 @@
 |2| @73
 |3| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
 |4| @29|║+0#0000001#ffd7ff255| |o|n|e| @5| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
-|5| @29|║+0#0000001#ffd7ff255| |t+0&#e0e0e08|w|o| +0&#ffd7ff255@5| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
+|5| @29|║+0#0000001#ffd7ff255| |t+0&#e0e0e08|w|o| @4| +0&#ffd7ff255| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |6| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |7| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
 |8| @73
--- a/src/testdir/dumps/Test_popupwin_menu_scroll_2.dump
+++ b/src/testdir/dumps/Test_popupwin_menu_scroll_2.dump
@@ -3,7 +3,7 @@
 |3| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
 |4| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |5| @29|║+0#0000001#ffd7ff255| |f|o|u|r| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
-|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| @29|║+0#0000001#ffd7ff255| |f+0&#e0e0e08|i|v|e| @3| +0&#ffd7ff255| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |7| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
 |8| @73
 |9| @73
--- a/src/testdir/dumps/Test_popupwin_menu_scroll_3.dump
+++ b/src/testdir/dumps/Test_popupwin_menu_scroll_3.dump
@@ -3,7 +3,7 @@
 |3| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
 |4| @29|║+0#0000001#ffd7ff255| |s|e|v|e|n| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |5| @29|║+0#0000001#ffd7ff255| |e|i|g|h|t| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
-|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| @29|║+0#0000001#ffd7ff255| |n+0&#e0e0e08|i|n|e| @3| +0&#ffd7ff255| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |7| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
 |8| @73
 |9| @73
--- a/src/testdir/dumps/Test_popupwin_menu_scroll_4.dump
+++ b/src/testdir/dumps/Test_popupwin_menu_scroll_4.dump
@@ -1,7 +1,7 @@
 >1+0&#ffffff0| @73
 |2| @73
 |3| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
-|4| @29|║+0#0000001#ffd7ff255| |s+0&#e0e0e08|e|v|e|n| +0&#ffd7ff255@3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
+|4| @29|║+0#0000001#ffd7ff255| |s+0&#e0e0e08|e|v|e|n| @2| +0&#ffd7ff255| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |5| @29|║+0#0000001#ffd7ff255| |e|i|g|h|t| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |6| @29|║+0#0000001#ffd7ff255| |n|i|n|e| @4| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |7| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
--- a/src/testdir/dumps/Test_popupwin_menu_scroll_5.dump
+++ b/src/testdir/dumps/Test_popupwin_menu_scroll_5.dump
@@ -1,7 +1,7 @@
 >1+0&#ffffff0| @73
 |2| @73
 |3| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
-|4| @29|║+0#0000001#ffd7ff255| |s+0&#e0e0e08|i|x| +0&#ffd7ff255@5| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
+|4| @29|║+0#0000001#ffd7ff255| |s+0&#e0e0e08|i|x| @4| +0&#ffd7ff255| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |5| @29|║+0#0000001#ffd7ff255| |s|e|v|e|n| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |6| @29|║+0#0000001#ffd7ff255| |e|i|g|h|t| @3| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |7| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
--- a/src/testdir/dumps/Test_popupwin_menu_scroll_6.dump
+++ b/src/testdir/dumps/Test_popupwin_menu_scroll_6.dump
@@ -1,7 +1,7 @@
 >1+0&#ffffff0| @73
 |2| @73
 |3| @29|╔+0#0000001#ffd7ff255|═@10|╗| +0#0000000#ffffff0@30
-|4| @29|║+0#0000001#ffd7ff255| |o+0&#e0e0e08|n|e| +0&#ffd7ff255@5| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
+|4| @29|║+0#0000001#ffd7ff255| |o+0&#e0e0e08|n|e| @4| +0&#ffd7ff255| +0#0000000#0000001|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |5| @29|║+0#0000001#ffd7ff255| |t|w|o| @5| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |6| @29|║+0#0000001#ffd7ff255| |t|h|r|e@1| @3| +0#0000000#a8a8a8255|║+0#0000001#ffd7ff255| +0#0000000#ffffff0@30
 |7| @29|╚+0#0000001#ffd7ff255|═@10|╝| +0#0000000#ffffff0@30
--- a/src/version.c
+++ b/src/version.c
@@ -778,6 +778,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1718,
+/**/
     1717,
 /**/
     1716,