Merge pull request #22590 from bfredl/status2

refactor(redraw): make cursor position use the "redraw later" pattern
This commit is contained in:
bfredl 2023-03-12 13:47:39 +01:00 committed by GitHub
commit e5f4394eb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 31 additions and 42 deletions

View File

@ -728,19 +728,15 @@ static void win_redr_border(win_T *wp)
/// Show current cursor info in ruler and various other places
///
/// @param always if false, only show ruler if position has changed.
void show_cursor_info(bool always)
void show_cursor_info_later(bool force)
{
if (!always && !redrawing()) {
return;
}
int state = get_real_state();
int empty_line = (State & MODE_INSERT) == 0
&& *ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false) == NUL;
// Only draw when something changed.
validate_virtcol_win(curwin);
if (always
if (force
|| curwin->w_cursor.lnum != curwin->w_stl_cursor.lnum
|| curwin->w_cursor.col != curwin->w_stl_cursor.col
|| curwin->w_virtcol != curwin->w_stl_virtcol
@ -750,27 +746,19 @@ void show_cursor_info(bool always)
|| curwin->w_topfill != curwin->w_stl_topfill
|| empty_line != curwin->w_stl_empty
|| state != curwin->w_stl_state) {
win_check_ns_hl(curwin);
if ((*p_stl != NUL || *curwin->w_p_stl != NUL)
&& (curwin->w_status_height || global_stl_height())) {
redraw_custom_statusline(curwin);
if ((curwin->w_status_height || global_stl_height())) {
curwin->w_redr_status = true;
} else {
win_redr_ruler(curwin);
redraw_cmdline = true;
}
if (*p_wbr != NUL || *curwin->w_p_wbr != NUL) {
win_redr_winbar(curwin);
curwin->w_redr_status = true;
}
if (need_maketitle
|| (p_icon && (stl_syntax & STL_IN_ICON))
if ((p_icon && (stl_syntax & STL_IN_ICON))
|| (p_title && (stl_syntax & STL_IN_TITLE))) {
maketitle();
}
win_check_ns_hl(NULL);
// Redraw the tab pages line if needed.
if (redraw_tabline) {
draw_tabline();
need_maketitle = true;
}
}
@ -2136,7 +2124,7 @@ void status_redraw_all(void)
bool is_stl_global = global_stl_height() != 0;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if ((!is_stl_global && wp->w_status_height) || (is_stl_global && wp == curwin)
if ((!is_stl_global && wp->w_status_height) || wp == curwin
|| wp->w_winbar_height) {
wp->w_redr_status = true;
redraw_later(wp, UPD_VALID);

View File

@ -1350,12 +1350,15 @@ void ins_redraw(bool ready)
}
pum_check_clear();
show_cursor_info_later(false);
if (must_redraw) {
update_screen();
} else if (clear_cmdline || redraw_cmdline) {
showmode(); // clear cmdline and show mode
} else {
redraw_statuslines();
if (clear_cmdline || redraw_cmdline || redraw_mode) {
showmode(); // clear cmdline and show mode
}
}
show_cursor_info(false);
setcursor();
emsg_on_display = false; // may remove error message now
}

View File

@ -3747,6 +3747,7 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T
update_topline(curwin);
validate_cursor();
redraw_later(curwin, UPD_SOME_VALID);
show_cursor_info_later(true);
update_screen();
highlight_match = false;
redraw_later(curwin, UPD_SOME_VALID);
@ -3765,7 +3766,6 @@ static int do_sub(exarg_T *eap, proftime_T timeout, long cmdpreview_ns, handle_T
_("replace with %s (y/n/a/q/l/^E/^Y)?"), sub);
msg_no_more = false;
msg_scroll = (int)i;
show_cursor_info(true);
if (!ui_has(kUIMessages)) {
ui_cursor_goto(msg_row, msg_col);
}

View File

@ -1306,16 +1306,20 @@ static void normal_redraw(NormalState *s)
update_topline(curwin);
validate_cursor();
show_cursor_info_later(false);
if (VIsual_active) {
redraw_curbuf_later(UPD_INVERTED); // update inverted part
update_screen();
} else if (must_redraw) {
update_screen();
} else if (redraw_cmdline || clear_cmdline || redraw_mode) {
showmode();
}
redraw_statuslines();
if (must_redraw) {
update_screen();
} else {
redraw_statuslines();
if (redraw_cmdline || clear_cmdline || redraw_mode) {
showmode();
}
}
if (need_maketitle) {
maketitle();
@ -1348,7 +1352,6 @@ static void normal_redraw(NormalState *s)
did_emsg = false;
msg_didany = false; // reset lines_left in msg_start()
may_clear_sb_text(); // clear scroll-back text on next msg
show_cursor_info(false);
setcursor();
}

View File

@ -2255,9 +2255,6 @@ static char *set_bool_option(const int opt_idx, char *const varp, const int valu
if ((int *)varp == &p_ru || (int *)varp == &p_sc) {
// in case 'ruler' or 'showcmd' changed
comp_col();
if ((int *)varp == &p_ru) {
win_redr_ruler(curwin);
}
}
if (curwin->w_curswant != MAXCOL
&& (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0) {

View File

@ -1221,7 +1221,6 @@ static void did_set_statusline(win_T *win, char **varp, char **gvarp, char **err
}
if (varp == &p_ruf && *errmsg == NULL) {
comp_col();
win_redr_ruler(curwin);
}
// add / remove window bars for 'winbar'
if (gvarp == &p_wbr) {

View File

@ -2340,7 +2340,6 @@ void showmatch(int c)
dollar_vcol = -1;
}
curwin->w_virtcol++; // do display ')' just before "$"
update_screen(); // show the new char first
colnr_T save_dollar_vcol = dollar_vcol;
int save_state = State;
@ -2349,7 +2348,8 @@ void showmatch(int c)
curwin->w_cursor = mpos; // move to matching char
*so = 0; // don't use 'scrolloff' here
*siso = 0; // don't use 'sidescrolloff' here
show_cursor_info(false);
show_cursor_info_later(false);
update_screen(); // show the new char
setcursor();
ui_flush();
// Restore dollar_vcol(), because setcursor() may call curs_rows()

View File

@ -152,7 +152,7 @@ describe('Screen', function()
~ |
~ |
~ |
> |
-- INSERT -- |
]])
end)

View File

@ -474,8 +474,7 @@ describe('ui/ext_messages', function()
]], msg_history={{
content = {{ "stuff" }},
kind = "echomsg",
}}, showmode={{ "-- INSERT --", 3 }},
messages={{
}}, messages={{
content = {{ "Press ENTER or type command to continue", 4}},
kind = "return_prompt"
}}}