Skip to content

Commit 1c20a2e

Browse files
committed
fix: close last window with q!, fixes #137; also refactor close_all_floats
1 parent 19a2683 commit 1c20a2e

File tree

2 files changed

+6
-37
lines changed

2 files changed

+6
-37
lines changed

lua/neo-tree.lua

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ M.win_enter_event = function()
397397
return
398398
end
399399

400+
-- if the new win is not a floating window, make sure all neo-tree floats are closed
401+
require("neo-tree").close_all("float")
402+
400403
if M.config.close_if_last_window then
401404
local tabnr = vim.api.nvim_get_current_tabpage()
402405
local wins = utils.get_value(M, "config.prior_windows", {})[tabnr]
@@ -407,7 +410,7 @@ M.win_enter_event = function()
407410
log.trace("win_count: ", win_count)
408411
if prior_exists and win_count == 1 and vim.o.filetype == "neo-tree" then
409412
log.trace("last window, closing")
410-
vim.api.nvim_win_close(0, true)
413+
vim.cmd("q!")
411414
return
412415
end
413416
end
@@ -582,17 +585,11 @@ M.setup = function(config, is_auto_config)
582585
manager.redraw(source_name)
583586
end
584587

585-
local event_handler = {
588+
events.subscribe({
586589
event = events.VIM_WIN_ENTER,
587590
handler = M.win_enter_event,
588591
id = "neo-tree-win-enter",
589-
}
590-
if config.open_files_in_last_window or config.close_if_last_window then
591-
events.subscribe(event_handler)
592-
else
593-
events.unsubscribe(event_handler)
594-
config.prior_windows = nil
595-
end
592+
})
596593

597594
if not is_auto_config and get_hijack_netrw_behavior() ~= "disabled" then
598595
vim.cmd("silent! autocmd! FileExplorer *")

lua/neo-tree/ui/renderer.lua

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -363,33 +363,6 @@ create_tree = function(state)
363363
})
364364
end
365365

366-
local auto_close_floats_is_set = false
367-
368-
local enable_auto_close_floats = function()
369-
if auto_close_floats_is_set then
370-
log.trace("Auto close floats is already set.")
371-
return
372-
end
373-
local event_handler = {
374-
event = events.VIM_WIN_ENTER,
375-
handler = function()
376-
local win_id = vim.api.nvim_get_current_win()
377-
local cfg = vim.api.nvim_win_get_config(win_id)
378-
if cfg.relative > "" or cfg.external then
379-
-- floating window, ignore
380-
log.trace("Ignoring floating window", cfg)
381-
return
382-
end
383-
log.trace("Closing all floating windows")
384-
require("neo-tree").close_all("float")
385-
end,
386-
id = "neo-tree-auto-close-floats",
387-
}
388-
log.trace("Enabling auto close floats")
389-
events.subscribe(event_handler)
390-
auto_close_floats_is_set = true
391-
end
392-
393366
create_window = function(state)
394367
local default_position = utils.resolve_config_option(state, "window.position", "left")
395368
state.current_position = state.current_position or default_position
@@ -445,7 +418,6 @@ create_window = function(state)
445418

446419
-- why is this necessary?
447420
vim.api.nvim_set_current_win(win.winid)
448-
enable_auto_close_floats()
449421
elseif state.current_position == "split" then
450422
local winid = vim.api.nvim_get_current_win()
451423
local bufnr = vim.fn.bufnr(bufname)

0 commit comments

Comments
 (0)