Skip to content

Commit

Permalink
patch 9.0.0245: mechanism to prevent recursive screen updating is inc…
Browse files Browse the repository at this point in the history
…omplete

Problem:    Mechanism to prevent recursive screen updating is incomplete.
Solution:   Add "redraw_not_allowed" and set it in build_stl_str_hl().
            (issue #10952)
  • Loading branch information
brammool committed Aug 22, 2022
1 parent f768c3d commit 471c0fa
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 40 deletions.
23 changes: 11 additions & 12 deletions src/buffer.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/change.c
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/digraph.c
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/drawscreen.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ex_docmd.c
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/globals.h
Expand Up @@ -600,9 +600,13 @@ EXTERN int diff_need_scrollbind INIT(= FALSE);
#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.
Expand Down
18 changes: 9 additions & 9 deletions src/highlight.c
Expand Up @@ -939,7 +939,7 @@ highlight_set_ctermfg(int idx, int color, int is_normal_group)
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);
}
Expand All @@ -962,7 +962,7 @@ highlight_set_ctermbg(int idx, int color, int is_normal_group)
if (!gui.in_use && !gui.starting)
#endif
{
must_redraw = UPD_CLEAR;
set_must_redraw(UPD_CLEAR);
if (color >= 0)
{
int dark = -1;
Expand Down Expand Up @@ -1005,7 +1005,7 @@ highlight_set_ctermul(int idx, int color, int is_normal_group)
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);
}
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -1939,15 +1939,15 @@ 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",
&gui.scroll_fg_pixel, &gui.scroll_bg_pixel,
FALSE, FALSE, FALSE))
{
gui_new_scrollbar_colors();
must_redraw = UPD_CLEAR;
set_must_redraw(UPD_CLEAR);
}
# endif
}
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -2545,7 +2545,7 @@ get_attr_entry(garray_T *table, attrentry_T *aep)

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);
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Expand Up @@ -686,7 +686,7 @@ vim_main2(void)
&& !gui.in_use
#endif
)
must_redraw = UPD_CLEAR;
set_must_redraw(UPD_CLEAR);
else
{
screenclear(); // clear screen
Expand Down
5 changes: 2 additions & 3 deletions src/message.c
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

/*
Expand Down
9 changes: 3 additions & 6 deletions src/misc1.c
Expand Up @@ -413,10 +413,8 @@ plines_win_nofold(win_T *wp, linenr_T lnum)
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;

Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/proto/drawscreen.pro
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/screen.c
Expand Up @@ -2906,7 +2906,7 @@ screenalloc(int doclear)
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
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -731,6 +731,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
245,
/**/
244,
/**/
Expand Down

0 comments on commit 471c0fa

Please sign in to comment.