commit 3341ab07764e9cda95e89880da579ea3ebb7f9b7
parent aa47c8efa90f4df0c44e517fd0fb44ef9b76b8c1
Author: luukvbaal <luukvbaal@gmail.com>
Date: Mon, 14 Apr 2025 13:19:07 +0200
fix(marks): clamp conceal_lines corrected line number #33464
Problem: Line number corrected for conceal_lines may be set beyond eob
when the last buffer line is concealed, causing ml_get errors.
Solution: Avoid setting line number beyond eob.
Diffstat:
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
@@ -1705,7 +1705,8 @@ static void win_update(win_T *wp)
// incurring scrolling even though wp->w_topline is still the same.
// Compare against an adjusted topline instead:
linenr_T topline_conceal = wp->w_topline;
- while (decor_conceal_line(wp, topline_conceal - 1, false)) {
+ while (topline_conceal < buf->b_ml.ml_line_count
+ && decor_conceal_line(wp, topline_conceal - 1, false)) {
topline_conceal++;
hasFolding(wp, topline_conceal, NULL, &topline_conceal);
}
@@ -2320,6 +2321,7 @@ static void win_update(win_T *wp)
// Adjust "wl_lastlnum" for concealed lines below the last line in the window.
while (row == wp->w_grid.rows
+ && wp->w_lines[idx].wl_lastlnum < buf->b_ml.ml_line_count
&& decor_conceal_line(wp, wp->w_lines[idx].wl_lastlnum, false)) {
wp->w_lines[idx].wl_lastlnum++;
hasFolding(wp, wp->w_lines[idx].wl_lastlnum, NULL, &wp->w_lines[idx].wl_lastlnum);
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c
@@ -1661,7 +1661,8 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
}
// Mouse row reached, adjust lnum for concealed lines.
- while (decor_conceal_line(win, lnum - 1, false)) {
+ while (lnum < win->w_buffer->b_ml.ml_line_count
+ && decor_conceal_line(win, lnum - 1, false)) {
lnum++;
hasFolding(win, lnum, NULL, &lnum);
}
diff --git a/test/functional/ui/mouse_spec.lua b/test/functional/ui/mouse_spec.lua
@@ -2086,8 +2086,15 @@ describe('ui/mouse/input', function()
it('below a concealed line #33450', function()
api.nvim_set_option_value('conceallevel', 2, {})
api.nvim_buf_set_extmark(0, api.nvim_create_namespace(''), 1, 0, { conceal_lines = '' })
- api.nvim_input_mouse('right', 'press', '', 0, 1, 0)
- api.nvim_input_mouse('right', 'release', '', 0, 1, 0)
+ api.nvim_input_mouse('left', 'press', '', 0, 1, 0)
+ api.nvim_input_mouse('left', 'release', '', 0, 1, 0)
eq(3, fn.line('.'))
+ -- No error when clicking below last line that is concealed.
+ screen:try_resize(80, 10) -- Prevent hit-enter
+ api.nvim_set_option_value('cmdheight', 3, {})
+ local count = api.nvim_buf_line_count(0)
+ api.nvim_buf_set_extmark(0, 1, count - 1, 0, { conceal_lines = '' })
+ api.nvim_input_mouse('left', 'press', '', 0, count, 0)
+ eq('', api.nvim_get_vvar('errmsg'))
end)
end)