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.
diff --git a/src/popupwin.c b/src/popupwin.c
index 47a5c78..d22c00d 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -451,6 +451,22 @@
 	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 @@
     static void
 popup_highlight_curline(win_T *wp)
 {
-    int	    id;
-    char    buf[100];
+    int	    sign_id = 0;
+    char_u  *sign_name = popup_get_sign_name(wp);
 
-    match_delete(wp, 1, FALSE);
+    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 @@
 	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 @@
 
     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 @@
 	++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 @@
     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 @@
 	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 @@
     // 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);
diff --git a/src/proto/sign.pro b/src/proto/sign.pro
index 50b74aa..7362cc0 100644
--- a/src/proto/sign.pro
+++ b/src/proto/sign.pro
@@ -9,7 +9,9 @@
 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);
diff --git a/src/screen.c b/src/screen.c
index 5cffdf1..7998710 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -5366,6 +5366,8 @@
 			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
 		}
diff --git a/src/sign.c b/src/sign.c
index bf238d9..2cec269 100644
--- a/src/sign.c
+++ b/src/sign.c
@@ -1025,10 +1025,19 @@
 }
 
 /*
+ * 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 @@
     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 @@
 /*
  * 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 @@
 		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 @@
     {
 	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 @@
 	if (name == NULL)
 	    return;
 
-	if (sign_undefine_by_name(name) == OK)
+	if (sign_undefine_by_name(name, TRUE) == OK)
 	    rettv->vval.v_number = 0;
     }
 }
diff --git a/src/testdir/dumps/Test_popupwin_menu_01.dump b/src/testdir/dumps/Test_popupwin_menu_01.dump
index bc15520..3f09f3e 100644
--- 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
diff --git a/src/testdir/dumps/Test_popupwin_menu_02.dump b/src/testdir/dumps/Test_popupwin_menu_02.dump
index 594daf4..464e276 100644
--- 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
diff --git a/src/testdir/dumps/Test_popupwin_menu_04.dump b/src/testdir/dumps/Test_popupwin_menu_04.dump
index bfa660c..30706a7 100644
--- 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
diff --git a/src/testdir/dumps/Test_popupwin_menu_scroll_1.dump b/src/testdir/dumps/Test_popupwin_menu_scroll_1.dump
index 8db8436..95d020f 100644
--- 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
diff --git a/src/testdir/dumps/Test_popupwin_menu_scroll_2.dump b/src/testdir/dumps/Test_popupwin_menu_scroll_2.dump
index 2b8d270..935e3b4 100644
--- 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
diff --git a/src/testdir/dumps/Test_popupwin_menu_scroll_3.dump b/src/testdir/dumps/Test_popupwin_menu_scroll_3.dump
index ca95812..00fe0c8 100644
--- 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
diff --git a/src/testdir/dumps/Test_popupwin_menu_scroll_4.dump b/src/testdir/dumps/Test_popupwin_menu_scroll_4.dump
index dece66a..d019c86 100644
--- 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
diff --git a/src/testdir/dumps/Test_popupwin_menu_scroll_5.dump b/src/testdir/dumps/Test_popupwin_menu_scroll_5.dump
index 0410eb9..132137a 100644
--- 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
diff --git a/src/testdir/dumps/Test_popupwin_menu_scroll_6.dump b/src/testdir/dumps/Test_popupwin_menu_scroll_6.dump
index 55726bb..6718bb3 100644
--- 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
diff --git a/src/version.c b/src/version.c
index 47b044f..e9e0446 100644
--- a/src/version.c
+++ b/src/version.c
@@ -778,6 +778,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1718,
+/**/
     1717,
 /**/
     1716,