Skip to content
Closed
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
24 changes: 16 additions & 8 deletions lua/mini/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1544,14 +1544,8 @@ H.explorer_refresh = function(explorer, opts)
explorer = H.explorer_sync_cursor_and_branch(explorer, depth)
end

-- Unregister windows from showed buffers, as they might get outdated
for _, win_id in ipairs(explorer.windows) do
-- NOTE: window can be invalid if it was showing buffer that was deleted
if H.is_valid_win(win_id) then
local buf_id = vim.api.nvim_win_get_buf(win_id)
H.opened_buffers[buf_id].win_id = nil
end
end
-- Unregister windows from shown buffers, as they might get outdated
explorer = H.explorer_unregister_windows(explorer)

-- Compute depth range which is possible to show in current window
local depth_range = H.compute_visible_depth_range(explorer, explorer.opts)
Expand Down Expand Up @@ -1684,6 +1678,20 @@ H.explorer_sync_cursor_and_branch = function(explorer, depth)
return explorer
end

H.explorer_unregister_windows = function(explorer)
local valid_windows = {}
for i, win_id in ipairs(explorer.windows) do
-- NOTE: window can be invalid if it was showing buffer that was deleted
if H.is_valid_win(win_id) then
local buf_id = vim.api.nvim_win_get_buf(win_id)
H.opened_buffers[buf_id].win_id = nil
table.insert(valid_windows, win_id)
end
end
explorer.windows = valid_windows
return explorer
end

H.explorer_go_in_range = function(explorer, buf_id, from_line, to_line)
-- Compute which entries to go in: all files and only last directory
local files, path, line = {}, nil, nil
Expand Down
13 changes: 13 additions & 0 deletions tests/test_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5733,6 +5733,19 @@ T['Events']['`MiniFilesWindowUpdate` can customize internally set window config
expect_screenshot()
end

T['Events']['MiniFilesWindowUpdate with preview works with `get_explorer_state()` after `undo`'] = function()
child.lua('MiniFiles.config.windows.preview = true')
child.lua([[
vim.api.nvim_create_autocmd('User', {
pattern = 'MiniFilesWindowUpdate',
callback = function() MiniFiles.get_explorer_state() end
})
]])
open()
type_keys('o', '<Esc>', 'u')
eq(#get_explorer_state().windows, 2)
end

T['Events']['`MiniFilesActionCreate` triggers'] = function()
track_event('MiniFilesActionCreate')

Expand Down
Loading