diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-07-11 07:15:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-11 07:15:46 +0800 |
commit | db8fe63a9398efd57c3ff28aa3d93e45fb70ee1a (patch) | |
tree | 31107910712b0454160b28441b7945a8167628c7 /src/nvim/plines.c | |
parent | 3750e5ed9c740a4334628c4a560d77c1dc2d0bfd (diff) | |
download | rneovim-db8fe63a9398efd57c3ff28aa3d93e45fb70ee1a.tar.gz rneovim-db8fe63a9398efd57c3ff28aa3d93e45fb70ee1a.tar.bz2 rneovim-db8fe63a9398efd57c3ff28aa3d93e45fb70ee1a.zip |
feat(api): add nvim_win_text_height (#24236)
It uses the same code as "scroll_delta" of "win_viewport" UI event to
calculate text height, but is more flexible.
Diffstat (limited to 'src/nvim/plines.c')
-rw-r--r-- | src/nvim/plines.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/nvim/plines.c b/src/nvim/plines.c index 476e5b2b7d..df1414bc8f 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -600,14 +600,14 @@ static int win_nolbr_chartabsize(chartabsize_T *cts, int *headp) /// Get the number of screen lines a range of text will take in window "wp". /// -/// @param start_lnum first line number -/// @param start_vcol >= 0: virtual column on "start_lnum" where counting starts, -/// rounded down to full screen lines -/// < 0: count a full "start_lnum", including filler lines above -/// @param end_lnum last line number -/// @param end_vcol >= 0: virtual column on "end_lnum" where counting ends, -/// rounded up to full screen lines -/// < 0: count a full "end_lnum", not including fillers lines below +/// @param start_lnum Starting line number, 1-based inclusive. +/// @param start_vcol >= 0: Starting virtual column index on "start_lnum", +/// 0-based inclusive, rounded down to full screen lines. +/// < 0: Count a full "start_lnum", including filler lines above. +/// @param end_lnum Ending line number, 1-based inclusive. +/// @param end_vcol >= 0: Ending virtual column index on "end_lnum", +/// 0-based exclusive, rounded up to full screen lines. +/// < 0: Count a full "end_lnum", not including fillers lines below. int64_t win_text_height(win_T *const wp, const linenr_T start_lnum, const int64_t start_vcol, const linenr_T end_lnum, const int64_t end_vcol) { @@ -620,39 +620,39 @@ int64_t win_text_height(win_T *const wp, const linenr_T start_lnum, const int64_ width2 = MAX(width2, 0); } - int64_t size = 0; - int64_t height_nofill = 0; + int64_t height_sum = 0; + int64_t height_cur_nofill = 0; linenr_T lnum = start_lnum; 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; + height_cur_nofill = folded ? 1 : plines_win_nofill(wp, lnum, false); + height_sum += height_cur_nofill; const int64_t row_off = (start_vcol < width1 || width2 <= 0) ? 0 : 1 + (start_vcol - width1) / width2; - size -= MIN(row_off, height_nofill); + height_sum -= MIN(row_off, height_cur_nofill); lnum = lnum_next + 1; } while (lnum <= end_lnum) { 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; + height_cur_nofill = folded ? 1 : plines_win_nofill(wp, lnum, false); + height_sum += win_get_fill(wp, lnum) + height_cur_nofill; lnum = lnum_next + 1; } if (end_vcol >= 0) { - size -= height_nofill; + height_sum -= height_cur_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); + height_sum += MIN(row_off, height_cur_nofill); } - return size; + return height_sum; } |