mirror of
https://github.com/neovim/neovim.git
synced 2025-12-23 14:48:58 +00:00
fix(ui-ext): "scroll_delta" handle topfill and skipcol (#24249)
This commit is contained in:
@@ -1226,6 +1226,8 @@ struct window_S {
|
||||
|
||||
bool w_viewport_invalid;
|
||||
linenr_T w_viewport_last_topline; // topline when the viewport was last updated
|
||||
linenr_T w_viewport_last_topfill; // topfill when the viewport was last updated
|
||||
linenr_T w_viewport_last_skipcol; // skipcol when the viewport was last updated
|
||||
|
||||
// w_cline_height is the number of physical lines taken by the buffer line
|
||||
// that the cursor is on. We use this to avoid extra calls to plines_win().
|
||||
|
||||
@@ -595,3 +595,52 @@ static int win_nolbr_chartabsize(chartabsize_T *cts, int *headp)
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
int64_t win_get_text_height(win_T *const wp, const linenr_T first, const linenr_T last,
|
||||
const int64_t start_vcol, const int64_t end_vcol)
|
||||
{
|
||||
int width1 = 0;
|
||||
int width2 = 0;
|
||||
if (start_vcol >= 0 || end_vcol >= 0) {
|
||||
width1 = wp->w_width_inner - win_col_off(wp);
|
||||
width2 = width1 + win_col_off2(wp);
|
||||
width1 = MAX(width1, 0);
|
||||
width2 = MAX(width2, 0);
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
int64_t height_nofill = 0;
|
||||
linenr_T lnum = first;
|
||||
|
||||
if (start_vcol >= 0) {
|
||||
linenr_T lnum_next = lnum;
|
||||
const bool folded = hasFoldingWin(wp, lnum, &lnum, &lnum_next, true, NULL);
|
||||
height_nofill = folded ? 1 : plines_win_nofill(wp, lnum, false);
|
||||
size += height_nofill;
|
||||
const int64_t row_off = (start_vcol < width1 || width2 <= 0)
|
||||
? 0
|
||||
: 1 + (start_vcol - width1) / width2;
|
||||
size -= MIN(row_off, height_nofill);
|
||||
lnum = lnum_next + 1;
|
||||
}
|
||||
|
||||
while (lnum <= last) {
|
||||
linenr_T lnum_next = lnum;
|
||||
const bool folded = hasFoldingWin(wp, lnum, &lnum, &lnum_next, true, NULL);
|
||||
height_nofill = folded ? 1 : plines_win_nofill(wp, lnum, false);
|
||||
size += win_get_fill(wp, lnum) + height_nofill;
|
||||
lnum = lnum_next + 1;
|
||||
}
|
||||
|
||||
if (end_vcol >= 0) {
|
||||
size -= height_nofill;
|
||||
const int64_t row_off = end_vcol == 0
|
||||
? 0
|
||||
: (end_vcol <= width1 || width2 <= 0)
|
||||
? 1
|
||||
: 1 + (end_vcol - width1 + width2 - 1) / width2;
|
||||
size += MIN(row_off, height_nofill);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -1037,22 +1037,31 @@ void ui_ext_win_viewport(win_T *wp)
|
||||
// interact with incomplete final line? Diff filler lines?
|
||||
botline = wp->w_buffer->b_ml.ml_line_count;
|
||||
}
|
||||
int scroll_delta = 0;
|
||||
if (wp->w_viewport_last_topline > line_count) {
|
||||
scroll_delta -= wp->w_viewport_last_topline - line_count;
|
||||
wp->w_viewport_last_topline = line_count;
|
||||
int64_t delta = 0;
|
||||
linenr_T last_topline = wp->w_viewport_last_topline;
|
||||
int last_topfill = wp->w_viewport_last_topfill;
|
||||
int64_t last_skipcol = wp->w_viewport_last_skipcol;
|
||||
if (last_topline > line_count) {
|
||||
delta -= last_topline - line_count;
|
||||
last_topline = line_count;
|
||||
last_topfill = 0;
|
||||
last_skipcol = MAXCOL;
|
||||
}
|
||||
if (wp->w_topline < wp->w_viewport_last_topline) {
|
||||
scroll_delta -= plines_m_win(wp, wp->w_topline, wp->w_viewport_last_topline - 1);
|
||||
} else if (wp->w_topline > wp->w_viewport_last_topline
|
||||
&& wp->w_topline <= line_count) {
|
||||
scroll_delta += plines_m_win(wp, wp->w_viewport_last_topline, wp->w_topline - 1);
|
||||
if (wp->w_topline < last_topline
|
||||
|| (wp->w_topline == last_topline && wp->w_skipcol < last_skipcol)) {
|
||||
delta -= win_get_text_height(wp, wp->w_topline, last_topline, wp->w_skipcol, last_skipcol);
|
||||
} else if ((wp->w_topline > last_topline && wp->w_topline <= line_count)
|
||||
|| (wp->w_topline == last_topline && wp->w_skipcol > last_skipcol)) {
|
||||
delta += win_get_text_height(wp, last_topline, wp->w_topline, last_skipcol, wp->w_skipcol);
|
||||
}
|
||||
ui_call_win_viewport(wp->w_grid_alloc.handle, wp->handle, wp->w_topline - 1,
|
||||
botline, wp->w_cursor.lnum - 1, wp->w_cursor.col,
|
||||
line_count, scroll_delta);
|
||||
delta += last_topfill;
|
||||
delta -= wp->w_topfill;
|
||||
ui_call_win_viewport(wp->w_grid_alloc.handle, wp->handle, wp->w_topline - 1, botline,
|
||||
wp->w_cursor.lnum - 1, wp->w_cursor.col, line_count, delta);
|
||||
wp->w_viewport_invalid = false;
|
||||
wp->w_viewport_last_topline = wp->w_topline;
|
||||
wp->w_viewport_last_topfill = wp->w_topfill;
|
||||
wp->w_viewport_last_skipcol = wp->w_skipcol;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user