0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set

Problem:    Moving the cursor is slow when 'relativenumber' is set.
Solution:   Only redraw the number column, not all lines.
This commit is contained in:
Bram Moolenaar
2018-09-12 23:15:48 +02:00
parent 1b7fefcbce
commit bd9a53c06c
3 changed files with 210 additions and 188 deletions

View File

@@ -145,21 +145,25 @@ redraw_for_cursorline(win_T *wp)
# endif # endif
) )
{ {
if (wp->w_p_rnu)
// win_line() will redraw the number column only.
redraw_win_later(wp, VALID);
#ifdef FEAT_SYN_HL #ifdef FEAT_SYN_HL
if (!wp->w_p_rnu && wp->w_redr_type <= VALID && last_cursorline != 0) if (wp->w_p_cul)
{ {
// "last_cursorline" may be set for another window, worst case we if (wp->w_redr_type <= VALID && last_cursorline != 0)
// redraw too much. This is optimized for moving the cursor around {
// in the same window. // "last_cursorline" may be set for another window, worst case
// we redraw too much. This is optimized for moving the cursor
// around in the same window.
redrawWinline(wp, last_cursorline, FALSE); redrawWinline(wp, last_cursorline, FALSE);
redrawWinline(wp, wp->w_cursor.lnum, FALSE); redrawWinline(wp, wp->w_cursor.lnum, FALSE);
redraw_win_later(wp, VALID); redraw_win_later(wp, VALID);
} }
else else
#endif
redraw_win_later(wp, SOME_VALID); redraw_win_later(wp, SOME_VALID);
#ifdef FEAT_SYN_HL
last_cursorline = wp->w_cursor.lnum; last_cursorline = wp->w_cursor.lnum;
}
#endif #endif
} }
} }

View File

@@ -132,7 +132,7 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T
static void fill_foldcolumn(char_u *p, win_T *wp, int closed, linenr_T lnum); static void fill_foldcolumn(char_u *p, win_T *wp, int closed, linenr_T lnum);
static void copy_text_attr(int off, char_u *buf, int len, int attr); static void copy_text_attr(int off, char_u *buf, int len, int attr);
#endif #endif
static int win_line(win_T *, linenr_T, int, int, int nochange); static int win_line(win_T *, linenr_T, int, int, int nochange, int number_only);
static int char_needs_redraw(int off_from, int off_to, int cols); static int char_needs_redraw(int off_from, int off_to, int cols);
static void draw_vsep_win(win_T *wp, int row); static void draw_vsep_win(win_T *wp, int row);
#ifdef FEAT_STL_OPT #ifdef FEAT_STL_OPT
@@ -971,7 +971,8 @@ update_single_line(win_T *wp, linenr_T lnum)
start_search_hl(); start_search_hl();
prepare_search_hl(wp, lnum); prepare_search_hl(wp, lnum);
# endif # endif
win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); win_line(wp, lnum, row, row + wp->w_lines[j].wl_size,
FALSE, FALSE);
# if defined(FEAT_SEARCH_EXTRA) # if defined(FEAT_SEARCH_EXTRA)
end_search_hl(); end_search_hl();
# endif # endif
@@ -1881,7 +1882,7 @@ win_update(win_T *wp)
/* /*
* Update a line when it is in an area that needs updating, when it * Update a line when it is in an area that needs updating, when it
* has changes or w_lines[idx] is invalid. * has changes or w_lines[idx] is invalid.
* bot_start may be halfway a wrapped line after using * "bot_start" may be halfway a wrapped line after using
* win_del_lines(), check if the current line includes it. * win_del_lines(), check if the current line includes it.
* When syntax folding is being used, the saved syntax states will * When syntax folding is being used, the saved syntax states will
* already have been updated, we can't see where the syntax state is * already have been updated, we can't see where the syntax state is
@@ -2140,7 +2141,8 @@ win_update(win_T *wp)
/* /*
* Display one line. * Display one line.
*/ */
row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); row = win_line(wp, lnum, srow, wp->w_height,
mod_top == 0, FALSE);
#ifdef FEAT_FOLDING #ifdef FEAT_FOLDING
wp->w_lines[idx].wl_folded = FALSE; wp->w_lines[idx].wl_folded = FALSE;
@@ -2177,7 +2179,14 @@ win_update(win_T *wp)
} }
else else
{ {
/* This line does not need updating, advance to the next one */ if (wp->w_p_rnu)
{
// 'relativenumber' set: The text doesn't need to be drawn, but
// the number column nearly always does.
(void)win_line(wp, lnum, srow, wp->w_height, TRUE, TRUE);
}
// This line does not need to be drawn, advance to the next one.
row += wp->w_lines[idx++].wl_size; row += wp->w_lines[idx++].wl_size;
if (row > wp->w_height) /* past end of screen */ if (row > wp->w_height) /* past end of screen */
break; break;
@@ -3058,7 +3067,8 @@ win_line(
linenr_T lnum, linenr_T lnum,
int startrow, int startrow,
int endrow, int endrow,
int nochange UNUSED) /* not updating for changed text */ int nochange UNUSED, // not updating for changed text
int number_only) // only update the number column
{ {
int col = 0; /* visual column on screen */ int col = 0; /* visual column on screen */
unsigned off; /* offset in ScreenLines/ScreenAttrs */ unsigned off; /* offset in ScreenLines/ScreenAttrs */
@@ -3253,6 +3263,8 @@ win_line(
row = startrow; row = startrow;
screen_row = row + W_WINROW(wp); screen_row = row + W_WINROW(wp);
if (!number_only)
{
/* /*
* To speed up the loop below, set extra_check when there is linebreak, * To speed up the loop below, set extra_check when there is linebreak,
* trailing white space and/or syntax processing to be done. * trailing white space and/or syntax processing to be done.
@@ -3460,6 +3472,7 @@ win_line(
area_highlighting = TRUE; area_highlighting = TRUE;
attr = HL_ATTR(HLF_I); attr = HL_ATTR(HLF_I);
} }
}
#ifdef FEAT_DIFF #ifdef FEAT_DIFF
filler_lines = diff_check(wp, lnum); filler_lines = diff_check(wp, lnum);
@@ -3504,7 +3517,7 @@ win_line(
ptr = line; ptr = line;
#ifdef FEAT_SPELL #ifdef FEAT_SPELL
if (has_spell) if (has_spell && !number_only)
{ {
/* For checking first word with a capital skip white space. */ /* For checking first word with a capital skip white space. */
if (cap_col == 0) if (cap_col == 0)
@@ -3564,7 +3577,7 @@ win_line(
v = wp->w_skipcol; v = wp->w_skipcol;
else else
v = wp->w_leftcol; v = wp->w_leftcol;
if (v > 0) if (v > 0 && !number_only)
{ {
#ifdef FEAT_MBYTE #ifdef FEAT_MBYTE
char_u *prev_ptr = ptr; char_u *prev_ptr = ptr;
@@ -3707,7 +3720,7 @@ win_line(
*/ */
cur = wp->w_match_head; cur = wp->w_match_head;
shl_flag = FALSE; shl_flag = FALSE;
while (cur != NULL || shl_flag == FALSE) while ((cur != NULL || shl_flag == FALSE) && !number_only)
{ {
if (shl_flag == FALSE) if (shl_flag == FALSE)
{ {
@@ -4068,13 +4081,16 @@ win_line(
} }
} }
/* When still displaying '$' of change command, stop at cursor */ // When still displaying '$' of change command, stop at cursor.
if (dollar_vcol >= 0 && wp == curwin // When only displaying the (relative) line number and that's done,
// stop here.
if ((dollar_vcol >= 0 && wp == curwin
&& lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol
#ifdef FEAT_DIFF #ifdef FEAT_DIFF
&& filler_todo <= 0 && filler_todo <= 0
#endif #endif
) )
|| (number_only && draw_state > WL_NR))
{ {
screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width, screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
HAS_RIGHTLEFT(wp->w_p_rl)); HAS_RIGHTLEFT(wp->w_p_rl));

View File

@@ -794,6 +794,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
374,
/**/ /**/
373, 373,
/**/ /**/