diff src/terminal.c @ 19542:9e428147e4ee v8.2.0328

patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal Commit: https://github.com/vim/vim/commit/e52e0c89d1a6305beca3c01f89a4892dcb43bc71 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Feb 28 22:20:10 2020 +0100 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)
author Bram Moolenaar <Bram@vim.org>
date Fri, 28 Feb 2020 22:30:09 +0100
parents 274052873790
children 804322d6c6ba
line wrap: on
line diff
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -1796,6 +1796,27 @@ update_snapshot(term_T *term)
 }
 
 /*
+ * Loop over all windows in the current tab, and also curwin, which is not
+ * encountered when using a terminal in a popup window.
+ * Return TRUE if "*wp" was set to the next window.
+ */
+    static int
+for_all_windows_and_curwin(win_T **wp, int *did_curwin)
+{
+    if (*wp == NULL)
+	*wp = firstwin;
+    else if ((*wp)->w_next != NULL)
+	*wp = (*wp)->w_next;
+    else if (!*did_curwin)
+	*wp = curwin;
+    else
+	return FALSE;
+    if (*wp == curwin)
+	*did_curwin = TRUE;
+    return TRUE;
+}
+
+/*
  * If needed, add the current lines of the terminal to scrollback and to the
  * buffer.  Called after the job has ended and when switching to
  * Terminal-Normal mode.
@@ -1804,8 +1825,6 @@ update_snapshot(term_T *term)
     static void
 may_move_terminal_to_buffer(term_T *term, int redraw)
 {
-    win_T	    *wp;
-
     if (term->tl_vterm == NULL)
 	return;
 
@@ -1820,7 +1839,11 @@ may_move_terminal_to_buffer(term_T *term
 		       &term->tl_default_color.fg, &term->tl_default_color.bg);
 
     if (redraw)
-	FOR_ALL_WINDOWS(wp)
+    {
+	win_T	    *wp = NULL;
+	int	    did_curwin = FALSE;
+
+	while (for_all_windows_and_curwin(&wp, &did_curwin))
 	{
 	    if (wp->w_buffer == term->tl_buffer)
 	    {
@@ -1837,6 +1860,7 @@ may_move_terminal_to_buffer(term_T *term
 		redraw_win_later(wp, NOT_VALID);
 	    }
 	}
+    }
 }
 
 #if defined(FEAT_TIMERS) || defined(PROTO)
@@ -1920,6 +1944,7 @@ term_enter_normal_mode(void)
     check_cursor();
     if (coladvance(term->tl_cursor_pos.col) == FAIL)
 	coladvance(MAXCOL);
+    curwin->w_set_curswant = TRUE;
 
     // Display the same lines as in the terminal.
     curwin->w_topline = term->tl_scrollback_scrolled + 1;
@@ -1951,6 +1976,10 @@ term_enter_job_mode()
     if (term->tl_channel_closed)
 	cleanup_vterm(term);
     redraw_buf_and_status_later(curbuf, NOT_VALID);
+#ifdef FEAT_PROP_POPUP
+    if (WIN_IS_POPUP(curwin))
+	redraw_win_later(curwin, NOT_VALID);
+#endif
 }
 
 /*
@@ -2801,14 +2830,15 @@ handle_damage(VTermRect rect, void *user
     static void
 term_scroll_up(term_T *term, int start_row, int count)
 {
-    win_T		 *wp;
+    win_T		 *wp = NULL;
+    int			 did_curwin = FALSE;
     VTermColor		 fg, bg;
     VTermScreenCellAttrs attr;
     int			 clear_attr;
 
     vim_memset(&attr, 0, sizeof(attr));
 
-    FOR_ALL_WINDOWS(wp)
+    while (for_all_windows_and_curwin(&wp, &did_curwin))
     {
 	if (wp->w_buffer == term->tl_buffer)
 	{
@@ -2858,12 +2888,13 @@ handle_movecursor(
 	void *user)
 {
     term_T	*term = (term_T *)user;
-    win_T	*wp;
+    win_T	*wp = NULL;
+    int		did_curwin = FALSE;
 
     term->tl_cursor_pos = pos;
     term->tl_cursor_visible = visible;
 
-    FOR_ALL_WINDOWS(wp)
+    while (for_all_windows_and_curwin(&wp, &did_curwin))
     {
 	if (wp->w_buffer == term->tl_buffer)
 	    position_cursor(wp, &pos, FALSE);