fix: do not write to invalid buffer (#112)
This commit is contained in:
parent
fcd7a82ff7
commit
00f1e296b0
@ -245,7 +245,7 @@ end
|
|||||||
---@param content string concatenated content of the buffer
|
---@param content string concatenated content of the buffer
|
||||||
---@param opts? {focus?: boolean, stream?: boolean, scroll?: boolean, callback?: fun(): nil} whether to focus the result view
|
---@param opts? {focus?: boolean, stream?: boolean, scroll?: boolean, callback?: fun(): nil} whether to focus the result view
|
||||||
function Sidebar:update_content(content, opts)
|
function Sidebar:update_content(content, opts)
|
||||||
if not self.view.buf then
|
if not self.view.buf or not api.nvim_buf_is_valid(self.view.buf) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
opts = vim.tbl_deep_extend("force", { focus = true, scroll = true, stream = false, callback = nil }, opts or {})
|
opts = vim.tbl_deep_extend("force", { focus = true, scroll = true, stream = false, callback = nil }, opts or {})
|
||||||
@ -267,6 +267,9 @@ function Sidebar:update_content(content, opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
|
if not self.view.buf or not api.nvim_buf_is_valid(self.view.buf) then
|
||||||
|
return
|
||||||
|
end
|
||||||
scroll_to_bottom()
|
scroll_to_bottom()
|
||||||
local lines = vim.split(content, "\n")
|
local lines = vim.split(content, "\n")
|
||||||
api.nvim_set_option_value("modifiable", true, { buf = self.view.buf })
|
api.nvim_set_option_value("modifiable", true, { buf = self.view.buf })
|
||||||
@ -284,7 +287,7 @@ function Sidebar:update_content(content, opts)
|
|||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
if self.view.buf == nil then
|
if not self.view.buf or not api.nvim_buf_is_valid(self.view.buf) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local lines = vim.split(content, "\n")
|
local lines = vim.split(content, "\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user