Skip to content

Commit aea3110

Browse files
committed
fix(files): replace buffer before wiping when deleted, fixes #65
1 parent f5f8d9d commit aea3110

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

lua/neo-tree.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,13 @@ M.win_enter_event = function()
409409
log.trace("prior window is ", prior_exists)
410410
log.trace("win_count: ", win_count)
411411
if prior_exists and win_count == 1 and vim.o.filetype == "neo-tree" then
412-
log.trace("last window, closing")
413-
vim.cmd("q!")
414-
return
412+
local position = vim.api.nvim_buf_get_var(0, "neo_tree_position")
413+
if position ~= "split" then
414+
-- close_if_last_window just doesn't make sense for a split style
415+
log.trace("last window, closing")
416+
vim.cmd("q!")
417+
return
418+
end
415419
end
416420
end
417421

lua/neo-tree/sources/common/commands.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ local open_with_cmd = function(state, open_cmd, toggle_directory)
158158
local tree = state.tree
159159
local success, node = pcall(tree.get_node, tree)
160160
if not success and node then
161-
log.error("Could not get node.")
161+
log.debug("Could not get node.")
162162
return
163163
end
164164
if node.type == "directory" then

lua/neo-tree/sources/filesystem/lib/fs_actions.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,23 @@ local log = require("neo-tree.log")
1616
local M = {}
1717

1818
local function clear_buffer(path)
19-
for _, buf in pairs(api.nvim_list_bufs()) do
20-
if api.nvim_buf_get_name(buf) == path then
21-
pcall(vim.api.nvim_buf_delete, buf, { force = true })
19+
local buf = utils.find_buffer_by_name(path)
20+
local alt = vim.fn.bufnr("#")
21+
-- Check all windows to see if they are using the buffer
22+
for _, win in ipairs(vim.api.nvim_list_wins()) do
23+
if vim.api.nvim_win_get_buf(win) == buf then
24+
-- if there is no alternate buffer yet, create a blank one now
25+
if alt < 1 or alt == buf then
26+
alt = vim.api.nvim_create_buf(true, false)
27+
end
28+
-- replace the buffer displayed in this window with the alternate buffer
29+
vim.api.nvim_win_set_buf(win, alt)
2230
end
2331
end
32+
local success, msg = pcall(vim.api.nvim_buf_delete, buf, { force = true })
33+
if not success then
34+
log.error("Could not clear buffer: ", msg)
35+
end
2436
end
2537

2638
local function create_all_parents(path)
@@ -184,11 +196,11 @@ M.delete_node = function(path, callback)
184196
return false
185197
end
186198
else
187-
clear_buffer(child_path)
188199
local success = loop.fs_unlink(child_path)
189200
if not success then
190201
return false
191202
end
203+
clear_buffer(child_path)
192204
end
193205
end
194206
return loop.fs_rmdir(dir_path)

0 commit comments

Comments
 (0)