changeset 29812:68ef14b21d01 v9.0.0245

patch 9.0.0245: mechanism to prevent recursive screen updating is incomplete Commit: https://github.com/vim/vim/commit/471c0fa3eed4f6207d1cb7636970547bfd2eee26 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 22 15:19:16 2022 +0100 patch 9.0.0245: mechanism to prevent recursive screen updating is incomplete Problem: Mechanism to prevent recursive screen updating is incomplete. Solution: Add "redraw_not_allowed" and set it in build_stl_str_hl(). (issue #10952)
author Bram Moolenaar <Bram@vim.org>
date Mon, 22 Aug 2022 16:30:03 +0200
parents 4a20a89bf324
children dfd9d7ab4a5a
files src/buffer.c src/change.c src/digraph.c src/drawscreen.c src/ex_docmd.c src/globals.h src/highlight.c src/main.c src/message.c src/misc1.c src/proto/drawscreen.pro src/screen.c src/version.c
diffstat 13 files changed, 51 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -4228,10 +4228,15 @@ build_stl_str_hl(
     char_u	win_tmp[TMPLEN];
     char_u	*usefmt = fmt;
     stl_hlrec_T *sp;
-    int		save_must_redraw = must_redraw;
-    int		save_redr_type = curwin->w_redr_type;
+    int		save_redraw_not_allowed = redraw_not_allowed;
     int		save_KeyTyped = KeyTyped;
 
+    // When inside update_screen() we do not want redrawing a statusline,
+    // ruler, title, etc. to trigger another redraw, it may cause an endless
+    // loop.
+    if (updating_screen)
+	redraw_not_allowed = TRUE;
+
     if (stl_items == NULL)
     {
 	stl_items = ALLOC_MULT(stl_item_T, stl_items_len);
@@ -4968,11 +4973,11 @@ build_stl_str_hl(
 	else
 	    stl_items[curitem].stl_type = Empty;
 
+	if (num >= 0 || (!itemisflag && str != NULL && *str != NUL))
+	    prevchar_isflag = FALSE;	    // Item not NULL, but not a flag
+					    //
 	if (opt == STL_VIM_EXPR)
 	    vim_free(str);
-
-	if (num >= 0 || (!itemisflag && str && *str))
-	    prevchar_isflag = FALSE;	    // Item not NULL, but not a flag
 	curitem++;
     }
     *p = NUL;
@@ -5125,13 +5130,7 @@ build_stl_str_hl(
 	sp->userhl = 0;
     }
 
-    // When inside update_screen we do not want redrawing a statusline, ruler,
-    // title, etc. to trigger another redraw, it may cause an endless loop.
-    if (updating_screen)
-    {
-	must_redraw = save_must_redraw;
-	curwin->w_redr_type = save_redr_type;
-    }
+    redraw_not_allowed = save_redraw_not_allowed;
 
     // A user function may reset KeyTyped, restore it.
     KeyTyped = save_KeyTyped;
--- a/src/change.c
+++ b/src/change.c
@@ -559,7 +559,7 @@ changed_common(
 	    linenr_T last = lnume + xtra - 1;  // last line after the change
 #endif
 	    // Mark this window to be redrawn later.
-	    if (wp->w_redr_type < UPD_VALID)
+	    if (!redraw_not_allowed && wp->w_redr_type < UPD_VALID)
 		wp->w_redr_type = UPD_VALID;
 
 	    // Check if a change in the buffer has invalidated the cached
@@ -671,8 +671,7 @@ changed_common(
 
     // Call update_screen() later, which checks out what needs to be redrawn,
     // since it notices b_mod_set and then uses b_mod_*.
-    if (must_redraw < UPD_VALID)
-	must_redraw = UPD_VALID;
+    set_must_redraw(UPD_VALID);
 
     // when the cursor line is changed always trigger CursorMoved
     if (lnum <= curwin->w_cursor.lnum
--- a/src/digraph.c
+++ b/src/digraph.c
@@ -2028,7 +2028,7 @@ listdigraphs(int use_headers)
 
     // clear screen, because some digraphs may be wrong, in which case we
     // messed up ScreenLines
-    must_redraw = UPD_CLEAR;
+    set_must_redraw(UPD_CLEAR);
 }
 
     static void
--- a/src/drawscreen.c
+++ b/src/drawscreen.c
@@ -3154,7 +3154,7 @@ redraw_win_later(
     win_T	*wp,
     int		type)
 {
-    if (!exiting && wp->w_redr_type < type)
+    if (!exiting && !redraw_not_allowed && wp->w_redr_type < type)
     {
 	wp->w_redr_type = type;
 	if (type >= UPD_NOT_VALID)
@@ -3186,7 +3186,17 @@ redraw_all_later(int type)
     FOR_ALL_WINDOWS(wp)
 	redraw_win_later(wp, type);
     // This may be needed when switching tabs.
-    if (must_redraw < type)
+    set_must_redraw(type);
+}
+
+/*
+ * Set "must_redraw" to "type" unless it already has a higher value
+ * or it is currently not allowed.
+ */
+    void
+set_must_redraw(int type)
+{
+    if (!redraw_not_allowed && must_redraw < type)
 	must_redraw = type;
 }
 
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -7116,7 +7116,7 @@ do_exedit(
 #ifdef FEAT_GUI
 		hold_gui_events = 0;
 #endif
-		must_redraw = UPD_CLEAR;
+		set_must_redraw(UPD_CLEAR);
 		pending_exmode_active = TRUE;
 
 		main_loop(FALSE, TRUE);
--- a/src/globals.h
+++ b/src/globals.h
@@ -600,9 +600,13 @@ EXTERN int	diff_need_scrollbind INIT(= F
 #endif
 
 // While redrawing the screen this flag is set.  It means the screen size
-// ('lines' and 'rows') must not be changed.
+// ('lines' and 'rows') must not be changed and prevents recursive updating.
 EXTERN int	updating_screen INIT(= FALSE);
 
+// While computing a statusline and the like we do not want any w_redr_type or
+// must_redraw to be set.
+EXTERN int	redraw_not_allowed INIT(= FALSE);
+
 #ifdef MESSAGE_QUEUE
 // While closing windows or buffers messages should not be handled to avoid
 // using invalid windows or buffers.
--- a/src/highlight.c
+++ b/src/highlight.c
@@ -939,7 +939,7 @@ highlight_set_ctermfg(int idx, int color
 	if (!gui.in_use && !gui.starting)
 #endif
 	{
-	    must_redraw = UPD_CLEAR;
+	    set_must_redraw(UPD_CLEAR);
 	    if (termcap_active && color >= 0)
 		term_fg_color(color);
 	}
@@ -962,7 +962,7 @@ highlight_set_ctermbg(int idx, int color
 	if (!gui.in_use && !gui.starting)
 #endif
 	{
-	    must_redraw = UPD_CLEAR;
+	    set_must_redraw(UPD_CLEAR);
 	    if (color >= 0)
 	    {
 		int dark = -1;
@@ -1005,7 +1005,7 @@ highlight_set_ctermul(int idx, int color
 	if (!gui.in_use && !gui.starting)
 #endif
 	{
-	    must_redraw = UPD_CLEAR;
+	    set_must_redraw(UPD_CLEAR);
 	    if (termcap_active && color >= 0)
 		term_ul_color(color);
 	}
@@ -1919,7 +1919,7 @@ set_normal_colors(void)
 				 FALSE, TRUE, FALSE))
 	{
 	    gui_mch_new_colors();
-	    must_redraw = UPD_CLEAR;
+	    set_must_redraw(UPD_CLEAR);
 	}
 #  ifdef FEAT_GUI_X11
 	if (set_group_colors((char_u *)"Menu",
@@ -1929,7 +1929,7 @@ set_normal_colors(void)
 #   ifdef FEAT_MENU
 	    gui_mch_new_menu_colors();
 #   endif
-	    must_redraw = UPD_CLEAR;
+	    set_must_redraw(UPD_CLEAR);
 	}
 #   ifdef FEAT_BEVAL_GUI
 	if (set_group_colors((char_u *)"Tooltip",
@@ -1939,7 +1939,7 @@ set_normal_colors(void)
 #    ifdef FEAT_TOOLBAR
 	    gui_mch_new_tooltip_colors();
 #    endif
-	    must_redraw = UPD_CLEAR;
+	    set_must_redraw(UPD_CLEAR);
 	}
 #   endif
 	if (set_group_colors((char_u *)"Scrollbar",
@@ -1947,7 +1947,7 @@ set_normal_colors(void)
 			FALSE, FALSE, FALSE))
 	{
 	    gui_new_scrollbar_colors();
-	    must_redraw = UPD_CLEAR;
+	    set_must_redraw(UPD_CLEAR);
 	}
 #  endif
     }
@@ -1973,7 +1973,7 @@ set_normal_colors(void)
 		// color
 		cterm_normal_fg_gui_color = HL_TABLE()[idx].sg_gui_fg;
 		cterm_normal_bg_gui_color = HL_TABLE()[idx].sg_gui_bg;
-		must_redraw = UPD_CLEAR;
+		set_must_redraw(UPD_CLEAR);
 	    }
 	}
     }
@@ -2545,7 +2545,7 @@ get_attr_entry(garray_T *table, attrentr
 
 	clear_hl_tables();
 
-	must_redraw = UPD_CLEAR;
+	set_must_redraw(UPD_CLEAR);
 
 	for (i = 0; i < highlight_ga.ga_len; ++i)
 	    set_hl_attr(i);
--- a/src/main.c
+++ b/src/main.c
@@ -686,7 +686,7 @@ vim_main2(void)
 			&& !gui.in_use
 #endif
 					)
-	must_redraw = UPD_CLEAR;
+	set_must_redraw(UPD_CLEAR);
     else
     {
 	screenclear();			// clear screen
--- a/src/message.c
+++ b/src/message.c
@@ -1143,7 +1143,7 @@ wait_return(int redraw)
     FILE	*save_scriptout;
 
     if (redraw == TRUE)
-	must_redraw = UPD_CLEAR;
+	set_must_redraw(UPD_CLEAR);
 
     // If using ":silent cmd", don't wait for a return.  Also don't set
     // need_wait_return to do it later.
@@ -2490,8 +2490,7 @@ inc_msg_scrolled(void)
     }
 #endif
     ++msg_scrolled;
-    if (must_redraw < UPD_VALID)
-	must_redraw = UPD_VALID;
+    set_must_redraw(UPD_VALID);
 }
 
 /*
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -413,10 +413,8 @@ plines_win_nofold(win_T *wp, linenr_T ln
     clear_chartabsize_arg(&cts);
     col = (int)cts.cts_vcol;
 
-    /*
-     * If list mode is on, then the '$' at the end of the line may take up one
-     * extra column.
-     */
+    // If list mode is on, then the '$' at the end of the line may take up one
+    // extra column.
     if (wp->w_p_list && wp->w_lcs_chars.eol != NUL)
 	col += 1;
 
@@ -585,8 +583,7 @@ check_status(buf_T *buf)
 	if (wp->w_buffer == buf && wp->w_status_height)
 	{
 	    wp->w_redr_status = TRUE;
-	    if (must_redraw < UPD_VALID)
-		must_redraw = UPD_VALID;
+	    set_must_redraw(UPD_VALID);
 	}
 }
 
--- a/src/proto/drawscreen.pro
+++ b/src/proto/drawscreen.pro
@@ -13,6 +13,7 @@ void redraw_later(int type);
 void redraw_win_later(win_T *wp, int type);
 void redraw_later_clear(void);
 void redraw_all_later(int type);
+void set_must_redraw(int type);
 void redraw_curbuf_later(int type);
 void redraw_buf_later(buf_T *buf, int type);
 void redraw_buf_line_later(buf_T *buf, linenr_T lnum);
--- a/src/screen.c
+++ b/src/screen.c
@@ -2906,7 +2906,7 @@ give_up:
     screen_Rows = Rows;
     screen_Columns = Columns;
 
-    must_redraw = UPD_CLEAR;	// need to clear the screen later
+    set_must_redraw(UPD_CLEAR);	// need to clear the screen later
     if (doclear)
 	screenclear2();
 #ifdef FEAT_GUI
--- a/src/version.c
+++ b/src/version.c
@@ -732,6 +732,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    245,
+/**/
     244,
 /**/
     243,