refactor(redraw): no type argument in update_screen()

This was used in the past with assumption that curwin/curbuf
is "special" but this has not been true since basically forever
at this point.

Reduce NOT_VALID/CLEAR panic in options.lua . These should not
be set if an effect of the option is causing something
which by itself invokes redraw_later().
This commit is contained in:
bfredl 2022-09-26 15:17:10 +02:00
parent 1f2ded459a
commit 6679687bb3
21 changed files with 60 additions and 99 deletions

View File

@ -2720,7 +2720,7 @@ static void do_autocmd_focusgained(bool gained)
redrawcmdline();
} else if ((State & MODE_NORMAL) || (State & MODE_INSERT)) {
if (must_redraw != 0) {
update_screen(0);
update_screen();
}
setcursor();

View File

@ -2810,7 +2810,7 @@ void wildmenu_cleanup(CmdlineInfo *cclp)
p_ls = save_p_ls;
p_wmh = save_p_wmh;
last_status(false);
update_screen(UPD_VALID); // redraw the screen NOW
update_screen(); // redraw the screen NOW
redrawcmd();
save_p_ls = -1;
wild_menu_showing = 0;

View File

@ -341,7 +341,7 @@ void screen_resize(int width, int height)
}
if (State & MODE_CMDLINE) {
redraw_popupmenu = false;
update_screen(UPD_NOT_VALID);
update_screen();
redrawcmdline();
if (pum_drawn()) {
cmdline_pum_display(false);
@ -350,12 +350,12 @@ void screen_resize(int width, int height)
update_topline(curwin);
if (pum_drawn()) {
// TODO(bfredl): ins_compl_show_pum wants to redraw the screen first.
// For now make sure the nested update_screen(0) won't redraw the
// For now make sure the nested update_screen() won't redraw the
// pum at the old position. Try to untangle this later.
redraw_popupmenu = false;
ins_compl_show_pum();
}
update_screen(UPD_NOT_VALID);
update_screen();
if (redrawing()) {
setcursor();
}
@ -370,9 +370,7 @@ void screen_resize(int width, int height)
///
/// Most code shouldn't call this directly, rather use redraw_later() and
/// and redraw_all_later() to mark parts of the screen as needing a redraw.
///
/// @param type set to a UPD_NOT_VALID to force redraw of entire screen
int update_screen(int type)
int update_screen(void)
{
static bool did_intro = false;
bool is_stl_global = global_stl_height() > 0;
@ -389,9 +387,7 @@ int update_screen(int type)
diff_redraw(true);
}
// TODO(bfredl): completely get rid of using update_screen(UPD_XX_VALID)
// to redraw curwin
int curwin_type = MIN(type, UPD_NOT_VALID);
int type = 0;
if (must_redraw) {
if (type < must_redraw) { // use maximal type
@ -406,11 +402,6 @@ int update_screen(int type)
must_redraw = 0;
}
// Need to update w_lines[].
if (curwin->w_lines_valid == 0 && type < UPD_NOT_VALID) {
type = UPD_NOT_VALID;
}
// Postpone the redrawing when it's not needed and when being called
// recursively.
if (!redrawing() || updating_screen) {
@ -486,7 +477,6 @@ int update_screen(int type)
} else if (type != UPD_CLEAR) {
if (msg_scrolled > Rows - 5) { // redrawing is faster
type = UPD_NOT_VALID;
curwin_type = UPD_NOT_VALID;
} else {
check_for_delay(false);
grid_ins_lines(&default_grid, 0, msg_scrolled, Rows, 0, Columns);
@ -576,28 +566,6 @@ int update_screen(int type)
curwin->w_redr_type = UPD_NOT_VALID;
}
// Only start redrawing if there is really something to do.
// TODO(bfredl): more curwin special casing to get rid of.
// Change update_screen(UPD_INVERTED) to a wrapper function
// perhaps?
if (curwin_type == UPD_INVERTED) {
update_curswant();
}
if (curwin->w_redr_type < curwin_type
&& !((curwin_type == UPD_VALID
&& curwin->w_lines[0].wl_valid
&& curwin->w_topfill == curwin->w_old_topfill
&& curwin->w_botfill == curwin->w_old_botfill
&& curwin->w_topline == curwin->w_lines[0].wl_lnum)
|| (curwin_type == UPD_INVERTED
&& VIsual_active
&& curwin->w_old_cursor_lnum == curwin->w_cursor.lnum
&& curwin->w_old_visual_mode == VIsual_mode
&& (curwin->w_valid & VALID_VIRTCOL)
&& curwin->w_old_curswant == curwin->w_curswant))) {
curwin->w_redr_type = curwin_type;
}
// Redraw the tab pages line if needed.
if (redraw_tabline || type >= UPD_NOT_VALID) {
update_window_hl(curwin, type >= UPD_NOT_VALID);
@ -2034,7 +2002,7 @@ win_update_start:
}
}
/// Redraw a window later, with update_screen(type).
/// Redraw a window later, with wp->w_redr_type >= type.
///
/// Set must_redraw only if not already set to a higher value.
/// e.g. if must_redraw is UPD_CLEAR, type UPD_NOT_VALID will do nothing.

View File

@ -1286,7 +1286,7 @@ void ins_redraw(bool ready)
// a "(". The autocommand may also require a redraw, so it's done
// again below, unfortunately.
if (syntax_present(curwin) && must_redraw) {
update_screen(0);
update_screen();
}
// Make sure curswant is correct, an autocommand may call
// getcurpos()
@ -1348,7 +1348,7 @@ void ins_redraw(bool ready)
pum_check_clear();
if (must_redraw) {
update_screen(0);
update_screen();
} else if (clear_cmdline || redraw_cmdline) {
showmode(); // clear cmdline and show mode
}

View File

@ -3876,7 +3876,8 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T
update_topline(curwin);
validate_cursor();
update_screen(UPD_SOME_VALID);
redraw_later(curwin, UPD_SOME_VALID);
update_screen();
highlight_match = false;
redraw_later(curwin, UPD_SOME_VALID);

View File

@ -254,7 +254,7 @@ void do_exmode(void)
RedrawingDisabled--;
no_wait_return--;
redraw_all_later(UPD_NOT_VALID);
update_screen(UPD_NOT_VALID);
update_screen();
need_wait_return = false;
msg_scroll = save_msg_scroll;
}
@ -6090,9 +6090,10 @@ static void ex_redraw(exarg_T *eap)
if (eap->forceit) {
redraw_all_later(UPD_NOT_VALID);
redraw_cmdline = true;
} else if (VIsual_active) {
redraw_curbuf_later(UPD_INVERTED);
}
update_screen(eap->forceit ? UPD_NOT_VALID
: VIsual_active ? UPD_INVERTED : 0);
update_screen();
if (need_maketitle) {
maketitle();
}
@ -6132,7 +6133,10 @@ static void ex_redrawstatus(exarg_T *eap)
if (State & MODE_CMDLINE) {
redraw_statuslines();
} else {
update_screen(VIsual_active ? UPD_INVERTED : 0);
if (VIsual_active) {
redraw_curbuf_later(UPD_INVERTED);
}
update_screen();
}
RedrawingDisabled = r;
p_lz = p;

View File

@ -501,7 +501,8 @@ static void may_do_incsearch_highlighting(int firstc, long count, incsearch_stat
curwin->w_redr_status = true;
}
update_screen(UPD_SOME_VALID);
redraw_later(curwin, UPD_SOME_VALID);
update_screen();
highlight_match = false;
restore_last_search_pattern();
@ -588,7 +589,7 @@ static void finish_incsearch_highlighting(int gotesc, incsearch_state_T *s, bool
validate_cursor(); // needed for TAB
redraw_all_later(UPD_SOME_VALID);
if (call_update_screen) {
update_screen(UPD_SOME_VALID);
update_screen();
}
}
}
@ -1376,7 +1377,8 @@ static int may_do_command_line_next_incsearch(int firstc, long count, incsearch_
validate_cursor();
highlight_match = true;
save_viewstate(curwin, &s->old_viewstate);
update_screen(UPD_NOT_VALID);
redraw_later(curwin, UPD_NOT_VALID);
update_screen();
highlight_match = false;
redrawcmdline();
curwin->w_cursor = s->match_end;
@ -2336,7 +2338,7 @@ static bool cmdpreview_may_show(CommandLineState *s)
if (cmdpreview_type != 0) {
int save_rd = RedrawingDisabled;
RedrawingDisabled = 0;
update_screen(UPD_SOME_VALID);
update_screen();
RedrawingDisabled = save_rd;
}
@ -2406,7 +2408,9 @@ static int command_line_changed(CommandLineState *s)
} else {
cmdpreview = false;
if (prev_cmdpreview) {
update_screen(UPD_SOME_VALID); // Clear 'inccommand' preview.
// TODO(bfredl): add an immediate redraw flag for cmdline mode which will trigger
// at next wait-for-input
update_screen(); // Clear 'inccommand' preview.
}
if (s->xpc.xp_context == EXPAND_NOTHING && (KeyTyped || vpeekc() == NUL)) {
may_do_incsearch_highlighting(s->firstc, s->count, &s->is_state);

View File

@ -34,7 +34,6 @@ local redraw_flags={
current_window_only='P_RWINONLY',
current_buffer='P_RBUF',
all_windows='P_RALL',
everything='P_RCLR',
curswant='P_CURSWANT',
ui_option='P_UI_OPTION',
}

View File

@ -2601,7 +2601,7 @@ static int vgetorpeek(bool advance)
// input buffer (e.g., termresponse).
if (((State & MODE_INSERT) != 0 || p_lz) && (State & MODE_CMDLINE) == 0
&& advance && must_redraw != 0 && !need_wait_return) {
update_screen(0);
update_screen();
setcursor(); // put cursor back where it belongs
}

View File

@ -1228,7 +1228,7 @@ void ins_compl_show_pum(void)
do_cmdline_cmd("if exists('g:loaded_matchparen')|3match none|endif");
// Update the screen before drawing the popup menu over it.
update_screen(0);
update_screen();
int cur = -1;
bool array_changed = false;
@ -1648,7 +1648,7 @@ int ins_compl_bs(void)
ins_compl_restart();
}
// ins_compl_restart() calls update_screen(0) which may invalidate the pointer
// ins_compl_restart() calls update_screen() which may invalidate the pointer
// TODO(bfredl): get rid of random update_screen() calls deep inside completion logic
line = get_cursor_line_ptr();
@ -1759,7 +1759,7 @@ static void ins_compl_restart(void)
// update screen before restart.
// so if complete is blocked,
// will stay to the last popup menu and reduce flicker
update_screen(0);
update_screen(); // TODO(bfredl): no.
ins_compl_free();
compl_started = false;
compl_matches = 0;
@ -2048,7 +2048,7 @@ static bool ins_compl_stop(const int c, const int prev_mode, bool retval)
if (c == Ctrl_C && cmdwin_type != 0) {
// Avoid the popup menu remains displayed when leaving the
// command line window.
update_screen(0);
update_screen();
}
// Indent now if a key was typed that is in 'cinkeys'.
@ -3533,7 +3533,7 @@ static int ins_compl_next(bool allow_get_expansion, int count, bool insert_match
if (!allow_get_expansion) {
// redraw to show the user what was inserted
update_screen(0);
update_screen(); // TODO(bfredl): no!
// display the updated popup menu
ins_compl_show_pum();

View File

@ -130,16 +130,6 @@ static void redraw_for_cursorcolumn(win_T *wp)
}
}
// Update curwin->w_topline and redraw if necessary.
// Used to update the screen before printing a message.
void update_topline_redraw(void)
{
update_topline(curwin);
if (must_redraw) {
update_screen(0);
}
}
// Update curwin->w_topline to move the cursor onto the screen.
void update_topline(win_T *wp)
{

View File

@ -636,7 +636,7 @@ static void normal_redraw_mode_message(NormalState *s)
// Showmode() will clear keep_msg, but we want to use it anyway.
// First update w_topline.
setcursor();
update_screen(0);
update_screen();
// now reset it, otherwise it's put in the history again
keep_msg = kmsg;
@ -1284,9 +1284,9 @@ static void normal_redraw(NormalState *s)
if (VIsual_active) {
redraw_curbuf_later(UPD_INVERTED); // update inverted part
update_screen(0);
update_screen();
} else if (must_redraw) {
update_screen(0);
update_screen();
} else if (redraw_cmdline || clear_cmdline || redraw_mode) {
showmode();
}
@ -1841,7 +1841,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
if (jump_flags) {
jump_flags = jump_to_mouse(jump_flags, NULL, which_button);
redraw_curbuf_later(VIsual_active ? UPD_INVERTED : UPD_VALID);
update_screen(0);
update_screen();
setcursor();
ui_flush(); // Update before showing popup menu
}

View File

@ -2220,7 +2220,8 @@ void op_insert(oparg_T *oap, long count1)
// vis block is still marked. Get rid of it now.
curwin->w_cursor.lnum = oap->start.lnum;
update_screen(UPD_INVERTED);
redraw_curbuf_later(UPD_INVERTED);
update_screen();
if (oap->motion_type == kMTBlockWise) {
// When 'virtualedit' is used, need to insert the extra spaces before
@ -2772,7 +2773,10 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
}
// redisplay now, so message is not deleted
update_topline_redraw();
update_topline(curwin);
if (must_redraw) {
update_screen();
}
if (yank_type == kMTBlockWise) {
smsg(NGETTEXT("block of %" PRId64 " line yanked%s",
"block of %" PRId64 " lines yanked%s", yanklines),

View File

@ -2634,9 +2634,8 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf,
/// Called after an option changed: check if something needs to be redrawn.
void check_redraw(uint32_t flags)
{
// Careful: P_RCLR and P_RALL are a combination of other P_ flags
bool doclear = (flags & P_RCLR) == P_RCLR;
bool all = ((flags & P_RALL) == P_RALL || doclear);
// Careful: P_RALL is a combination of other P_ flags
bool all = (flags & P_RALL) == P_RALL;
if ((flags & P_RSTAT) || all) { // mark all status lines and window bars dirty
status_redraw_all();
@ -2651,9 +2650,7 @@ void check_redraw(uint32_t flags)
if (flags & P_RWINONLY) {
redraw_later(curwin, UPD_NOT_VALID);
}
if (doclear) {
redraw_all_later(UPD_CLEAR);
} else if (all) {
if (all) {
redraw_all_later(UPD_NOT_VALID);
}
}

View File

@ -20,7 +20,7 @@
-- lists: (nil), comma, onecomma, flags, flagscomma
-- scopes: global, buffer, window
-- redraw options: statuslines, current_window, curent_window_only,
-- current_buffer, all_windows, everything, curswant
-- current_buffer, all_windows, curswant
-- defaults: {condition=#if condition, if_true=default, if_false=default}
-- #if condition:
-- string: #ifdef string
@ -128,7 +128,6 @@ return {
full_name='background', abbreviation='bg',
short_desc=N_("\"dark\" or \"light\", used for highlight colors"),
type='string', scope={'global'},
redraw={'all_windows'},
varname='p_bg',
defaults={if_true="dark"}
},
@ -395,7 +394,6 @@ return {
short_desc=N_("number of columns in the display"),
type='number', scope={'global'},
no_mkrc=true,
redraw={'everything'},
varname='p_columns',
defaults={if_true=macros('DFLT_COLS')}
},
@ -422,7 +420,6 @@ return {
full_name='compatible', abbreviation='cp',
short_desc=N_("No description"),
type='bool', scope={'global'},
redraw={'all_windows'},
varname='p_force_off',
-- pri_mkrc isn't needed here, optval_default()
-- always returns TRUE for 'compatible'
@ -708,7 +705,6 @@ return {
full_name='equalalways', abbreviation='ea',
short_desc=N_("windows are automatically made the same size"),
type='bool', scope={'global'},
redraw={'all_windows'},
varname='p_ea',
defaults={if_true=true}
},
@ -1051,7 +1047,6 @@ return {
full_name='guioptions', abbreviation='go',
short_desc=N_("GUI: Which components and options are used"),
type='string', list='flags', scope={'global'},
redraw={'all_windows'},
enable_if=false,
},
{
@ -1195,7 +1190,6 @@ return {
full_name='inccommand', abbreviation='icm',
short_desc=N_("Live preview of substitution"),
type='string', scope={'global'},
redraw={'all_windows'},
varname='p_icm',
defaults={if_true="nosplit"}
},
@ -1403,7 +1397,6 @@ return {
short_desc=N_("of lines in the display"),
type='number', scope={'global'},
no_mkrc=true,
redraw={'everything'},
varname='p_lines',
defaults={if_true=macros('DFLT_ROWS')}
},
@ -2023,7 +2016,6 @@ return {
full_name='scrolloff', abbreviation='so',
short_desc=N_("minimum nr. of lines above and below cursor"),
type='number', scope={'global', 'window'},
redraw={'all_windows'},
varname='p_so',
defaults={if_true=0}
},
@ -2260,7 +2252,6 @@ return {
full_name='sidescrolloff', abbreviation='siso',
short_desc=N_("min. nr. of columns to left and right of cursor"),
type='number', scope={'global', 'window'},
redraw={'all_windows'},
varname='p_siso',
defaults={if_true=0}
},
@ -2453,7 +2444,7 @@ return {
short_desc=N_("custom format for the console tab pages line"),
type='string', scope={'global'},
modelineexpr=true,
redraw={'all_windows'},
redraw={'statuslines'},
varname='p_tal',
defaults={if_true=""}
},

View File

@ -818,7 +818,7 @@ static bool pum_set_selected(int n, int repeat)
// TODO(bfredl): can simplify, get rid of the flag munging?
// or at least eliminate extra redraw before win_enter()?
pum_is_visible = false;
update_screen(0);
update_screen();
pum_is_visible = true;
if (!resized && win_valid(curwin_save)) {
@ -830,7 +830,7 @@ static bool pum_set_selected(int n, int repeat)
// May need to update the screen again when there are
// autocommands involved.
pum_is_visible = false;
update_screen(0);
update_screen();
pum_is_visible = true;
}
}

View File

@ -2784,7 +2784,10 @@ static void qf_jump_print_msg(qf_info_T *qi, int qf_index, qfline_T *qf_ptr, buf
// Update the screen before showing the message, unless the screen
// scrolled up.
if (!msg_scrolled) {
update_topline_redraw();
update_topline(curwin);
if (must_redraw) {
update_screen();
}
}
snprintf((char *)IObuff, IOSIZE, _("(%d of %d)%s%s: "), qf_index,
qf_get_curlist(qi)->qf_count,

View File

@ -2321,7 +2321,7 @@ void showmatch(int c)
dollar_vcol = -1;
}
curwin->w_virtcol++; // do display ')' just before "$"
update_screen(UPD_VALID); // show the new char first
update_screen(); // show the new char first
save_dollar_vcol = dollar_vcol;
save_state = State;

View File

@ -57,7 +57,7 @@ getkey:
// Duplicate display updating logic in vgetorpeek()
if (((State & MODE_INSERT) != 0 || p_lz) && (State & MODE_CMDLINE) == 0
&& must_redraw != 0 && !need_wait_return) {
update_screen(0);
update_screen();
setcursor(); // put cursor back where it belongs
}
// Flush screen updates before blocking

View File

@ -522,7 +522,7 @@ static int terminal_check(VimState *state)
terminal_check_cursor();
if (must_redraw) {
update_screen(0);
update_screen();
}
if (need_maketitle) { // Update title in terminal-mode. #7248

View File

@ -138,7 +138,7 @@ bool ui_comp_should_draw(void)
///
/// TODO(bfredl): later on the compositor should just use win_float_pos events,
/// though that will require slight event order adjustment: emit the win_pos
/// events in the beginning of update_screen(0), rather than in ui_flush()
/// events in the beginning of update_screen(), rather than in ui_flush()
bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width, bool valid,
bool on_top)
{