feat: do not close preview when switching dirs (#277)

* feat: do not close preview when cd into dir

* refactor: add helper method to run function after oil buffer loads

* Keep preview window open

* Remove some test logic

* Use `run_after_load` when moving to parent directory

* Remove unnecessary update of current window

* refactor: create helper function for updating preview

---------

Co-authored-by: Steven Arcangeli <stevearc@stevearc.com>
This commit is contained in:
Lucas Eras Paiva 2024-01-21 22:32:02 -06:00 committed by GitHub
parent f0315c101f
commit bf753c3e3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 6 deletions

View file

@ -774,4 +774,26 @@ M.get_visual_range = function()
return { start_lnum = start_lnum, end_lnum = end_lnum }
end
---@param bufnr integer
---@param callback fun()
M.run_after_load = function(bufnr, callback)
if bufnr == 0 then
bufnr = vim.api.nvim_get_current_buf()
end
if vim.b[bufnr].oil_ready then
callback()
else
local autocmd_id
autocmd_id = vim.api.nvim_create_autocmd("User", {
pattern = "OilEnter",
callback = function(args)
if args.data.buf == bufnr then
callback()
vim.api.nvim_del_autocmd(autocmd_id)
end
end,
})
end
end
return M