mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
vim-patch:9.0.1747: screenpos() may cause unnecessary redraw (#24792)
Problem: screenpos() may cause unnecessary redraw.
Solution: Don't unnecessarily reset VALID_WROW flag.
VALID_WROW flag is only used by two functions: validate_cursor() and
cursor_valid(), and cursor_valid() is only used once in ex_sleep().
When adjust_plines_for_skipcol() was first added in patch 9.0.0640, it
was called in two functions: comp_botline() and curs_rows().
- comp_botline() is called in two places:
- onepage(), which resets VALID_WROW flag immediately afterwards.
- validate_botline_win(), where resetting a VALID_ flag is strange.
- curs_rows() is called in two places:
- curs_columns(), which sets VALID_WROW flag afterwards.
- validate_cline_row(), which is only used by GUI mouse focus.
Therefore resetting VALID_WROW there doesn't seem to do anything useful.
Also, a w_skipcol check (which resets VALID_WROW flag) was added to
check_cursor_moved() in patch 9.0.0734, which seems to make more sense
than resetting that flag in the middle of a computation.
While at it make adjust_plines_for_skipcol() and textpos2screenpos() a
bit less confusing:
- Make adjust_plines_for_skipcol() return "off" instead of "n - off".
- Use 0-based "row" in textpos2screenpos() until W_WINROW is added.
closes: vim/vim#12832
6235a109c4
This commit is contained in:
@@ -2112,7 +2112,7 @@ static void win_update(win_T *wp, DecorProviders *providers)
|
||||
new_rows++;
|
||||
} else if (l == wp->w_topline) {
|
||||
int n = plines_win_nofill(wp, l, false) + wp->w_topfill;
|
||||
n = adjust_plines_for_skipcol(wp, n);
|
||||
n -= adjust_plines_for_skipcol(wp);
|
||||
if (n > wp->w_height_inner) {
|
||||
n = wp->w_height_inner;
|
||||
}
|
||||
|
@@ -57,26 +57,19 @@ typedef struct {
|
||||
# include "move.c.generated.h"
|
||||
#endif
|
||||
|
||||
/// Reduce "n" for the screen lines skipped with "wp->w_skipcol".
|
||||
int adjust_plines_for_skipcol(win_T *wp, int n)
|
||||
/// Get the number of screen lines skipped with "wp->w_skipcol".
|
||||
int adjust_plines_for_skipcol(win_T *wp)
|
||||
{
|
||||
if (wp->w_skipcol == 0) {
|
||||
return n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int off = 0;
|
||||
int width = wp->w_width_inner - win_col_off(wp);
|
||||
if (wp->w_skipcol >= width) {
|
||||
off++;
|
||||
int skip = wp->w_skipcol - width;
|
||||
width += win_col_off2(wp);
|
||||
while (skip >= width) {
|
||||
off++;
|
||||
skip -= width;
|
||||
}
|
||||
return (wp->w_skipcol - width) / (width + win_col_off2(wp)) + 1;
|
||||
}
|
||||
wp->w_valid &= ~VALID_WROW;
|
||||
return n - off;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Return how many lines "lnum" will take on the screen, taking into account
|
||||
@@ -86,7 +79,7 @@ static int plines_correct_topline(win_T *wp, linenr_T lnum, linenr_T *nextp, boo
|
||||
{
|
||||
int n = plines_win_full(wp, lnum, nextp, foldedp, true, false);
|
||||
if (lnum == wp->w_topline) {
|
||||
n = adjust_plines_for_skipcol(wp, n);
|
||||
n -= adjust_plines_for_skipcol(wp);
|
||||
}
|
||||
if (n > wp->w_height_inner) {
|
||||
return wp->w_height_inner;
|
||||
@@ -1075,17 +1068,17 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
|
||||
linenr_T lnum = pos->lnum;
|
||||
if (lnum >= wp->w_topline && lnum <= wp->w_botline) {
|
||||
is_folded = hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
|
||||
row = plines_m_win(wp, wp->w_topline, lnum - 1, false) + 1;
|
||||
row = plines_m_win(wp, wp->w_topline, lnum - 1, false);
|
||||
// "row" should be the screen line where line "lnum" begins, which can
|
||||
// be negative if "lnum" is "w_topline" and "w_skipcol" is non-zero.
|
||||
row = adjust_plines_for_skipcol(wp, row);
|
||||
row -= adjust_plines_for_skipcol(wp);
|
||||
// Add filler lines above this buffer line.
|
||||
row += lnum == wp->w_topline ? wp->w_topfill : win_get_fill(wp, lnum);
|
||||
visible_row = true;
|
||||
} else if (!local || lnum < wp->w_topline) {
|
||||
row = 0;
|
||||
} else {
|
||||
row = wp->w_height_inner;
|
||||
row = wp->w_height_inner - 1;
|
||||
}
|
||||
|
||||
bool existing_row = (lnum > 0 && lnum <= wp->w_buffer->b_ml.ml_line_count);
|
||||
@@ -1093,7 +1086,7 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
|
||||
if ((local || visible_row) && existing_row) {
|
||||
const colnr_T off = win_col_off(wp);
|
||||
if (is_folded) {
|
||||
row += local ? 0 : wp->w_winrow + wp->w_winrow_off;
|
||||
row += (local ? 0 : wp->w_winrow + wp->w_winrow_off) + 1;
|
||||
coloff = (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1 + off;
|
||||
} else {
|
||||
assert(lnum == pos->lnum);
|
||||
@@ -1114,9 +1107,9 @@ void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp,
|
||||
|
||||
col -= wp->w_leftcol;
|
||||
|
||||
if (col >= 0 && col < wp->w_width_inner && row > 0 && row <= wp->w_height_inner) {
|
||||
if (col >= 0 && col < wp->w_width_inner && row >= 0 && row < wp->w_height_inner) {
|
||||
coloff = col - scol + (local ? 0 : wp->w_wincol + wp->w_wincol_off) + 1;
|
||||
row += local ? 0 : wp->w_winrow + wp->w_winrow_off;
|
||||
row += (local ? 0 : wp->w_winrow + wp->w_winrow_off) + 1;
|
||||
} else {
|
||||
// character is left, right or below of the window
|
||||
scol = ccol = ecol = 0;
|
||||
|
Reference in New Issue
Block a user