Skip to content

Commit dc77f48

Browse files
committed
fix: Views should dispose of their own buffers even when in use
1 parent b3a8a4f commit dc77f48

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lua/diffview/lib.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,17 @@ function M.get_prev_non_view_tabpage()
195195
end
196196

197197
---@param bufnr integer
198+
---@param ignore? vcs.File[]
198199
---@return boolean
199-
function M.is_buf_in_use(bufnr)
200+
function M.is_buf_in_use(bufnr, ignore)
200201
for _, view in ipairs(M.views) do
201202
if view:instanceof(StandardView.__get()) then
202203
---@cast view StandardView
203204
for _, file in ipairs(view.cur_entry and view.cur_entry.layout:files() or {}) do
204205
if file:is_valid() and file.bufnr == bufnr then
205-
return true
206+
if not (ignore and vim.tbl_contains(ignore, file)) then
207+
return true
208+
end
206209
end
207210
end
208211
end

lua/diffview/vcs/file.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function File:destroy(force)
108108
self.active = false
109109
self:detach_buffer()
110110

111-
if force or self.rev.type ~= RevType.LOCAL and not lib.is_buf_in_use(self.bufnr) then
111+
if force or self.rev.type ~= RevType.LOCAL and not lib.is_buf_in_use(self.bufnr, { self }) then
112112
File.safe_delete_buf(self.bufnr)
113113
end
114114
end
@@ -368,7 +368,7 @@ function File:dispose_buffer()
368368
if self.bufnr and api.nvim_buf_is_loaded(self.bufnr) then
369369
self:detach_buffer()
370370

371-
if not lib.is_buf_in_use(self.bufnr) then
371+
if not lib.is_buf_in_use(self.bufnr, { self }) then
372372
File.safe_delete_buf(self.bufnr)
373373
end
374374

0 commit comments

Comments
 (0)