Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lua/mini/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -922,11 +922,6 @@ MiniFiles.close = function()
-- Trigger appropriate event
H.trigger_event('MiniFilesExplorerClose')

-- Focus on target window
explorer = H.explorer_ensure_target_window(explorer)
-- - Use `pcall()` because window might still be invalid
pcall(vim.api.nvim_set_current_win, explorer.target_window)

-- Update currently shown cursors
explorer = H.explorer_update_cursors(explorer)

Expand All @@ -951,6 +946,11 @@ MiniFiles.close = function()
H.explorer_path_history[explorer.anchor] = explorer
H.opened_explorers[explorer.tabpage_id] = nil

-- Focus on target window
explorer = H.explorer_ensure_target_window(explorer)
-- - Use `pcall()` because window might still be invalid
pcall(vim.api.nvim_set_current_win, explorer.target_window)

-- Return `true` indicating success in closing
return true
end
Expand Down Expand Up @@ -1427,6 +1427,9 @@ H.track_dir_edit = function(data)
if vim.api.nvim_get_current_buf() ~= data.buf then return end

if vim.b.minifiles_processed_dir then
-- Only delete directory buffer explicitly when explorer is closed
if H.explorer_get() ~= nil then return end

-- Smartly delete directory buffer if already visited
local alt_buf = vim.fn.bufnr('#')
-- - Setting alternative buffer is enough for the "directory buffer" to be
Expand Down
26 changes: 26 additions & 0 deletions tests/test_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6369,6 +6369,32 @@ T['Default explorer']['handles forcing other window as current'] = function()
if child.fn.has('nvim-0.10') == 1 then eq(child.api.nvim_get_current_win(), init_win_id) end
end

T['Default explorer']['keeps directory buffer open when number of windows decreases'] = function()
local validate = function(fn_str)
child.cmd('edit ' .. make_test_path('nested'))

local buffers = child.api.nvim_list_bufs()
local dir_buffer_id = buffers[1]
eq(child.fn.isdirectory(child.api.nvim_buf_get_name(dir_buffer_id)), 1)

go_in()
go_in()
child.lua(fn_str)

-- Assert directory buffer still present
eq(child.api.nvim_buf_is_valid(dir_buffer_id), true)
-- Assert directory buffer deleted
close()
eq(child.api.nvim_buf_is_valid(dir_buffer_id), false)
end
-- Ensure enough space for 3 windows
child.set_size(5, 90)
-- Shrink number of windows using refresh
validate('MiniFiles.refresh({ windows = { max_number = 1 } })')
-- Shrink number of windows using trim_left
validate('MiniFiles.trim_left()')
end

T['Internal helpers'] = new_set()

T['Internal helpers']['path normalization works'] = function()
Expand Down