mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(folds): error when deleting lines at end of buffer #35396
Problem:
with `foldmethod=expr foldexpr=v:lua.vim.treesitter.foldexpr()
foldminlines=0`, deleting lines at the end of the buffer always
reports an invalid top error, because the top value (i.e. the
start line number of the deletion) is always 1 greater than
the total line number of the modified buffer.
Solution:
remove the ml_line_count validation
(cherry picked from commit d73cfefed5)
			
			
This commit is contained in:
		| @@ -565,7 +565,7 @@ static int nlua_foldupdate(lua_State *lstate) | |||||||
|   } |   } | ||||||
|   // input is zero-based end-exclusive range |   // input is zero-based end-exclusive range | ||||||
|   linenr_T top = (linenr_T)luaL_checkinteger(lstate, 2) + 1; |   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"); |     return luaL_error(lstate, "invalid top"); | ||||||
|   } |   } | ||||||
|   linenr_T bot = (linenr_T)luaL_checkinteger(lstate, 3); |   linenr_T bot = (linenr_T)luaL_checkinteger(lstate, 3); | ||||||
|   | |||||||
| @@ -853,4 +853,16 @@ t2]]) | |||||||
|     command('set ft=c') |     command('set ft=c') | ||||||
|     eq(foldlevels, get_fold_levels()) |     eq(foldlevels, get_fold_levels()) | ||||||
|   end) |   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('o<Esc>dd') | ||||||
|  |     screen:expect([[ | ||||||
|  |       ^hello                                   | | ||||||
|  |                                               | | ||||||
|  |     ]]) | ||||||
|  |   end) | ||||||
| end) | end) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 tao
					tao