fix(api): use correct buffer for "range" in nvim__redraw (#28614)

This commit is contained in:
luukvbaal 2024-05-03 04:35:32 +02:00 committed by GitHub
parent 01e4a70d66
commit cf9f002f31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 14 deletions

View File

@ -2415,10 +2415,11 @@ void nvim__redraw(Dict(redraw) *opts, Error *err)
}); });
linenr_T first = (linenr_T)kv_A(opts->range, 0).data.integer + 1; linenr_T first = (linenr_T)kv_A(opts->range, 0).data.integer + 1;
linenr_T last = (linenr_T)kv_A(opts->range, 1).data.integer; linenr_T last = (linenr_T)kv_A(opts->range, 1).data.integer;
if (last < 0) { buf_T *rbuf = win ? win->w_buffer : (buf ? buf : curbuf);
last = buf->b_ml.ml_line_count; if (last == -1) {
last = rbuf->b_ml.ml_line_count;
} }
redraw_buf_range_later(win ? win->w_buffer : (buf ? buf : curbuf), first, last); redraw_buf_range_later(rbuf, first, last);
} }
if (opts->cursor) { if (opts->cursor) {

View File

@ -5195,28 +5195,27 @@ describe('API', function()
}) })
-- valid = true does not draw any lines on its own -- valid = true does not draw any lines on its own
exec_lua([[ exec_lua([[
lines = 0 _G.lines = 0
ns = vim.api.nvim_create_namespace('') ns = vim.api.nvim_create_namespace('')
on_win = function()
if do_win then
vim.api.nvim_buf_set_extmark(0, ns, 0, 0, { hl_group = 'IncSearch', end_col = 6 })
end
end
vim.api.nvim_set_decoration_provider(ns, { vim.api.nvim_set_decoration_provider(ns, {
on_win = on_win, on_win = function()
if _G.do_win then
vim.api.nvim_buf_set_extmark(0, ns, 0, 0, { hl_group = 'IncSearch', end_col = 6 })
end
end,
on_line = function() on_line = function()
lines = lines + 1 _G.lines = _G.lines + 1
end, end,
}) })
]]) ]])
local lines = exec_lua('return lines') local lines = exec_lua('return lines')
api.nvim__redraw({ buf = 0, valid = true, flush = true }) api.nvim__redraw({ buf = 0, valid = true, flush = true })
eq(lines, exec_lua('return lines')) eq(lines, exec_lua('return _G.lines'))
-- valid = false does -- valid = false does
api.nvim__redraw({ buf = 0, valid = false, flush = true }) api.nvim__redraw({ buf = 0, valid = false, flush = true })
neq(lines, exec_lua('return lines')) neq(lines, exec_lua('return _G.lines'))
-- valid = true does redraw lines if affected by on_win callback -- valid = true does redraw lines if affected by on_win callback
exec_lua('do_win = true') exec_lua('_G.do_win = true')
api.nvim__redraw({ buf = 0, valid = true, flush = true }) api.nvim__redraw({ buf = 0, valid = true, flush = true })
screen:expect({ screen:expect({
grid = [[ grid = [[
@ -5227,5 +5226,8 @@ describe('API', function()
13 | 13 |
]], ]],
}) })
-- takes buffer line count from correct buffer with "win" and {0, -1} "range"
api.nvim__redraw({ win = 0, range = { 0, -1 } })
n.assert_alive()
end) end)
end) end)