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:
parent
f0315c101f
commit
bf753c3e3f
2 changed files with 53 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue