patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal

Problem:    No redraw when leaving terminal-normal mode in a terminal popup
            window.
Solution:   Redraw the popup window. (closes #5708)
diff --git a/src/drawscreen.c b/src/drawscreen.c
index 6b755c8..17a385c 100644
--- a/src/drawscreen.c
+++ b/src/drawscreen.c
@@ -69,6 +69,9 @@
 #ifdef FEAT_STL_OPT
 static void redraw_custom_statusline(win_T *wp);
 #endif
+#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
+static int  did_update_one_window;
+#endif
 
 /*
  * Based on the current value of curwin->w_topline, transfer a screenfull
@@ -81,10 +84,8 @@
     int		type = type_arg;
     win_T	*wp;
     static int	did_intro = FALSE;
-#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
-    int		did_one;
-#endif
 #ifdef FEAT_GUI
+    int		did_one = FALSE;
     int		did_undraw = FALSE;
     int		gui_cursor_col = 0;
     int		gui_cursor_row = 0;
@@ -276,7 +277,7 @@
     // Go from top to bottom through the windows, redrawing the ones that need
     // it.
 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
-    did_one = FALSE;
+    did_update_one_window = FALSE;
 #endif
 #ifdef FEAT_SEARCH_EXTRA
     screen_search_hl.rm.regprog = NULL;
@@ -286,21 +287,11 @@
 	if (wp->w_redr_type != 0)
 	{
 	    cursor_off();
-#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
+#ifdef FEAT_GUI
 	    if (!did_one)
 	    {
 		did_one = TRUE;
-# ifdef FEAT_SEARCH_EXTRA
-		start_search_hl();
-# endif
-# ifdef FEAT_CLIPBOARD
-		// When Visual area changed, may have to update selection.
-		if (clip_star.available && clip_isautosel_star())
-		    clip_update_selection(&clip_star);
-		if (clip_plus.available && clip_isautosel_plus())
-		    clip_update_selection(&clip_plus);
-# endif
-#ifdef FEAT_GUI
+
 		// Remove the cursor before starting to do anything, because
 		// scrolling may make it difficult to redraw the text under
 		// it.
@@ -311,9 +302,9 @@
 		    gui_undraw_cursor();
 		    did_undraw = TRUE;
 		}
-#endif
 	    }
 #endif
+
 	    win_update(wp);
 	}
 
@@ -1422,6 +1413,25 @@
     proftime_T	syntax_tm;
 #endif
 
+#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
+    // This needs to be done only for the first window when update_screen() is
+    // called.
+    if (!did_update_one_window)
+    {
+	did_update_one_window = TRUE;
+# ifdef FEAT_SEARCH_EXTRA
+	start_search_hl();
+# endif
+# ifdef FEAT_CLIPBOARD
+	// When Visual area changed, may have to update selection.
+	if (clip_star.available && clip_isautosel_star())
+	    clip_update_selection(&clip_star);
+	if (clip_plus.available && clip_isautosel_plus())
+	    clip_update_selection(&clip_plus);
+# endif
+    }
+#endif
+
     type = wp->w_redr_type;
 
     if (type == NOT_VALID)
@@ -3025,6 +3035,11 @@
 	if (wp->w_buffer == buf)
 	    redraw_win_later(wp, type);
     }
+#if defined(FEAT_TERMINAL) && defined(FEAT_PROP_POPUP)
+    // terminal in popup window is not in list of windows
+    if (curwin->w_buffer == buf)
+	redraw_win_later(curwin, type);
+#endif
 }
 
 #if defined(FEAT_SIGNS) || defined(PROTO)