Skip to content

Commit

Permalink
fix(filesystem): ensure replacemnt for deleted buffer is a real file (#…
Browse files Browse the repository at this point in the history
…1176)

fixes #1174
  • Loading branch information
cseickel committed Oct 8, 2023
1 parent 7e2a3ca commit 6f8c499
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lua/neo-tree/sources/filesystem/lib/fs_actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,36 @@ local Path = require("plenary").path

local M = {}

local function find_replacement_buffer(for_buf)
local bufs = vim.api.nvim_list_bufs()

-- make sure the alternate buffer is at the top of the list
local alt = vim.fn.bufnr("#")
if alt ~= -1 and alt ~= for_buf then
table.insert(bufs, 1, alt)
end

-- find the first valid real file buffer
for _, buf in ipairs(bufs) do
if buf ~= for_buf then
local is_valid = vim.api.nvim_buf_is_valid(buf)
if is_valid then
local buftype = vim.api.nvim_buf_get_option(buf, "buftype")
if buftype == "" then
return buf
end
end
end
end
return -1
end

local function clear_buffer(path)
local buf = utils.find_buffer_by_name(path)
if buf < 1 then
return
end
local alt = vim.fn.bufnr("#")
local alt = find_replacement_buffer(buf)
-- Check all windows to see if they are using the buffer
for _, win in ipairs(vim.api.nvim_list_wins()) do
if vim.api.nvim_win_is_valid(win) and vim.api.nvim_win_get_buf(win) == buf then
Expand Down

0 comments on commit 6f8c499

Please sign in to comment.