mirror of
https://github.com/neovim/neovim.git
synced 2026-02-09 05:18:45 +00:00
fix(api): auto-load buffers in nvim_buf_set_* operations (#35046)
fix(api): auto-load buffers in nvim_buf_set_* operations Problem: Setting marks, lines, or text on unloaded buffers fails because ml_line_count is not accurate until the buffer is loaded. Solution: Add require_loaded_buffer() helper and use it in write operations (nvim_buf_set_lines, nvim_buf_set_text, nvim_buf_set_mark). These now auto-load buffers as needed.
This commit is contained in:
@@ -863,6 +863,7 @@ describe('api/buf', function()
|
||||
local new_bufnr = fn.bufnr('set_lines', true)
|
||||
lua_or_rpc.nvim_buf_set_lines(new_bufnr, 0, -1, false, {})
|
||||
eq({ '' }, lua_or_rpc.nvim_buf_get_lines(new_bufnr, 0, -1, false))
|
||||
eq(true, api.nvim_buf_is_loaded(new_bufnr))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -1809,6 +1810,14 @@ describe('api/buf', function()
|
||||
eq({ 'one', 'two' }, get_lines(0, 2, true))
|
||||
end)
|
||||
|
||||
it('auto-loads unloaded buffer', function()
|
||||
local new_bufnr = fn.bufnr('set_text', true)
|
||||
eq(false, api.nvim_buf_is_loaded(new_bufnr))
|
||||
api.nvim_buf_set_text(new_bufnr, 0, 0, 0, -1, { 'foo' })
|
||||
eq(true, api.nvim_buf_is_loaded(new_bufnr))
|
||||
eq({ 'foo' }, api.nvim_buf_get_lines(new_bufnr, 0, -1, false))
|
||||
end)
|
||||
|
||||
describe('handles topline', function()
|
||||
local screen
|
||||
before_each(function()
|
||||
@@ -2375,6 +2384,13 @@ describe('api/buf', function()
|
||||
it('fails when invalid buffer number is used', function()
|
||||
eq(false, pcall(api.nvim_buf_set_mark, 99, 'a', 1, 1, {}))
|
||||
end)
|
||||
it('auto-loads unloaded buffer', function()
|
||||
local new_bufnr = fn.bufnr('set_mark', true)
|
||||
eq(false, api.nvim_buf_is_loaded(new_bufnr))
|
||||
eq(true, api.nvim_buf_set_mark(new_bufnr, 'A', 0, 0, {}))
|
||||
eq(true, api.nvim_buf_is_loaded(new_bufnr))
|
||||
eq({ 0, 0 }, api.nvim_buf_get_mark(new_bufnr, 'A'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('nvim_buf_del_mark', function()
|
||||
|
||||
Reference in New Issue
Block a user