diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/buffer_defs.h | 2 | ||||
-rw-r--r-- | src/nvim/plines.c | 49 | ||||
-rw-r--r-- | src/nvim/window.c | 37 |
3 files changed, 74 insertions, 14 deletions
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index d92d425ed5..5e9652792a 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -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(). diff --git a/src/nvim/plines.c b/src/nvim/plines.c index eb1ae540a4..46bbbeeb07 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -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; +} diff --git a/src/nvim/window.c b/src/nvim/window.c index 20e9dfec07..f5533db385 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -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; - } - 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); - } - 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); + 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 < 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); + } + 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; } } |