fix: do not use nvim_buf_line_count on unloaded buffers (#2261)
This commit is contained in:
@@ -641,7 +641,18 @@ function make_entry.gen_from_buffer(opts)
|
|||||||
local readonly = vim.api.nvim_buf_get_option(entry.bufnr, "readonly") and "=" or " "
|
local readonly = vim.api.nvim_buf_get_option(entry.bufnr, "readonly") and "=" or " "
|
||||||
local changed = entry.info.changed == 1 and "+" or " "
|
local changed = entry.info.changed == 1 and "+" or " "
|
||||||
local indicator = entry.flag .. hidden .. readonly .. changed
|
local indicator = entry.flag .. hidden .. readonly .. changed
|
||||||
|
local lnum = 1
|
||||||
|
|
||||||
|
-- account for potentially stale lnum as getbufinfo might not be updated or from resuming buffers picker
|
||||||
|
if entry.info.lnum ~= 0 then
|
||||||
|
-- but make sure the buffer is loaded, otherwise line_count is 0
|
||||||
|
if vim.api.nvim_buf_is_loaded(entry.bufnr) then
|
||||||
local line_count = vim.api.nvim_buf_line_count(entry.bufnr)
|
local line_count = vim.api.nvim_buf_line_count(entry.bufnr)
|
||||||
|
lnum = math.max(math.min(entry.info.lnum, line_count), 1)
|
||||||
|
else
|
||||||
|
lnum = entry.info.lnum
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return make_entry.set_default_entry_mt({
|
return make_entry.set_default_entry_mt({
|
||||||
value = bufname,
|
value = bufname,
|
||||||
@@ -650,8 +661,7 @@ function make_entry.gen_from_buffer(opts)
|
|||||||
|
|
||||||
bufnr = entry.bufnr,
|
bufnr = entry.bufnr,
|
||||||
filename = bufname,
|
filename = bufname,
|
||||||
-- account for potentially stale lnum as getbufinfo might not be updated or from resuming buffers picker
|
lnum = lnum,
|
||||||
lnum = entry.info.lnum ~= 0 and math.max(math.min(entry.info.lnum, line_count), 1) or 1,
|
|
||||||
indicator = indicator,
|
indicator = indicator,
|
||||||
}, opts)
|
}, opts)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user