Skip to content
Open
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
8 changes: 6 additions & 2 deletions lua/mini/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1382,8 +1382,12 @@ H.track_dir_edit = function(data)
if vim.b.minifiles_processed_dir then
-- Smartly delete directory buffer if already visited
local alt_buf = vim.fn.bufnr('#')
if alt_buf ~= data.buf and vim.fn.buflisted(alt_buf) == 1 then vim.api.nvim_win_set_buf(0, alt_buf) end
return vim.api.nvim_buf_delete(data.buf, { force = true })
if alt_buf ~= data.buf and vim.fn.buflisted(alt_buf) == 1 then
vim.api.nvim_win_set_buf(0, alt_buf)
else
vim.api.nvim_buf_delete(data.buf, { force = true })
end
return
end

local path = vim.api.nvim_buf_get_name(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--|---------|---------|---------|---------|---------|---------|---------|---------|
01|┌MOCK_ROOT/tests/dir-files/common ─────────────────┐
02|│ .a-dir │
03|│ a-dir │
04|│ b-dir │
05|│ .a-file │
06|│ a-file │
07|│ A-file-2 │
08|│ b-file │
09|└──────────────────────────────────────────────────┘
10|~
11|~
12|~
13|~
14|~
15| 1,1 All

--|---------|---------|---------|---------|---------|---------|---------|---------|
01|01111111111111111111111111111111110000000000000000002222222222222222222222222222
02|03333333344444444444444444444444444444444444444444405555555555555555555555555555
03|06666666777777777777777777777777777777777777777777705555555555555555555555555555
04|06666666777777777777777777777777777777777777777777705555555555555555555555555555
05|07777777777777777777777777777777777777777777777777705555555555555555555555555555
06|07777777777777777777777777777777777777777777777777705555555555555555555555555555
07|07777777777777777777777777777777777777777777777777705555555555555555555555555555
08|07777777777777777777777777777777777777777777777777705555555555555555555555555555
09|00000000000000000000000000000000000000000000000000005555555555555555555555555555
10|55555555555555555555555555555555555555555555555555555555555555555555555555555555
11|55555555555555555555555555555555555555555555555555555555555555555555555555555555
12|55555555555555555555555555555555555555555555555555555555555555555555555555555555
13|55555555555555555555555555555555555555555555555555555555555555555555555555555555
14|55555555555555555555555555555555555555555555555555555555555555555555555555555555
15|88888888888888888888888888888888888888888888888888888888888888888888888888888888
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--|---------|---------|---------|---------|---------|---------|---------|---------|
01|a-file
02|~
03|~
04|~
05|~
06|~
07|~
08|~
09|~
10|~
11|~
12|~
13|~
14|~
15| 1,1 All

--|---------|---------|---------|---------|---------|---------|---------|---------|
01|00000000000000000000000000000000000000000000000000000000000000000000000000000000
02|11111111111111111111111111111111111111111111111111111111111111111111111111111111
03|11111111111111111111111111111111111111111111111111111111111111111111111111111111
04|11111111111111111111111111111111111111111111111111111111111111111111111111111111
05|11111111111111111111111111111111111111111111111111111111111111111111111111111111
06|11111111111111111111111111111111111111111111111111111111111111111111111111111111
07|11111111111111111111111111111111111111111111111111111111111111111111111111111111
08|11111111111111111111111111111111111111111111111111111111111111111111111111111111
09|11111111111111111111111111111111111111111111111111111111111111111111111111111111
10|11111111111111111111111111111111111111111111111111111111111111111111111111111111
11|11111111111111111111111111111111111111111111111111111111111111111111111111111111
12|11111111111111111111111111111111111111111111111111111111111111111111111111111111
13|11111111111111111111111111111111111111111111111111111111111111111111111111111111
14|11111111111111111111111111111111111111111111111111111111111111111111111111111111
15|22222222222222222222222222222222222222222222222222222222222222222222222222222222
47 changes: 47 additions & 0 deletions tests/test_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5740,6 +5740,53 @@ T['Default explorer']['works in `:edit .`'] = function()
child.expect_screenshot()
end

T['Default explorer']['deletes directory buffer if already visited(no alternate)'] = function()
-- Starting with empty buffer having id 1, open and close the explorer
child.cmd('edit ' .. test_dir_path)
close()

-- There should only be 1 buffer after closing the explorer
local bufs = child.api.nvim_list_bufs()
eq(#bufs, 1)

-- Assert that buffer with id 1 has been deleted, otherwise it would be for directory test_dir_path
local is_still_one = bufs[1] == 1
eq(is_still_one, false)
end

T['Default explorer']['deletes directory buffer if already visited'] = function()
-- Starting with listed buffer having id 1, open and close the explorer
child.cmd('edit ' .. test_file_path)
child.cmd('edit ' .. test_dir_path)
close()

-- There should only be 1 buffer after closing the explorer
local bufs = child.api.nvim_list_bufs()
eq(#bufs, 1)

-- Assert that the buffer id is still 1
local bufid = bufs[1]
eq(bufid, 1)
end

T['Default explorer']['does not crash on external `vim.api.nvim_set_current_win`'] = function()
-- BufEnter Autocommands for "*": Vim(append):Lua callback : Invalid buffer id: 2

child.cmd('edit ' .. test_file_path)
child.cmd('edit ' .. test_dir_path)

-- Mimic MiniPick when stopping the picker(H.picker_stop -> H.set_curwin)
child.lua([[
local win_id = vim.api.nvim_list_wins()[1] -- vim.api.nvim_get_current_win()
vim.api.nvim_set_current_win(win_id)
]])

child.expect_screenshot()
close()
child.expect_screenshot()
eq(#child.api.nvim_list_bufs(), 1)
end

T['Default explorer']['works in `:vsplit .`'] = function()
child.cmd('vsplit ' .. test_dir_path)
child.expect_screenshot()
Expand Down
Loading