diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 4a3b8596b3..a57ca059b7 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -563,7 +563,7 @@ static int nlua_foldupdate(lua_State *lstate) } // input is zero-based end-exclusive range linenr_T top = (linenr_T)luaL_checkinteger(lstate, 2) + 1; - if (top < 1 || top > win->w_buffer->b_ml.ml_line_count) { + if (top < 1) { return luaL_error(lstate, "invalid top"); } linenr_T bot = (linenr_T)luaL_checkinteger(lstate, 3); diff --git a/test/functional/treesitter/fold_spec.lua b/test/functional/treesitter/fold_spec.lua index a050b60328..d4a96bc28e 100644 --- a/test/functional/treesitter/fold_spec.lua +++ b/test/functional/treesitter/fold_spec.lua @@ -832,4 +832,16 @@ t2]]) command('set ft=c') eq(foldlevels, get_fold_levels()) end) + + it('no error when deleting lines at end of buffer with fml=0', function() + local screen = Screen.new(40, 2) + insert('hello') + parse('markdown') + command('set foldmethod=expr foldexpr=v:lua.vim.treesitter.foldexpr() foldminlines=0') + feed('odd') + screen:expect([[ + ^hello | + | + ]]) + end) end)