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/terminal.c b/src/terminal.c
index 342275e..d4c605e 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -1796,6 +1796,27 @@
}
/*
+ * 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 @@
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 @@
&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 @@
redraw_win_later(wp, NOT_VALID);
}
}
+ }
}
#if defined(FEAT_TIMERS) || defined(PROTO)
@@ -1920,6 +1944,7 @@
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 @@
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 @@
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 @@
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);