diff --git a/lua/oil/util.lua b/lua/oil/util.lua index be6afdeb..b19c003f 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -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 diff --git a/lua/oil/view.lua b/lua/oil/view.lua index 162c7826..30180ee7 100644 --- a/lua/oil/view.lua +++ b/lua/oil/view.lua @@ -710,6 +710,7 @@ end --- refetch nil|boolean Defaults to true ---@param callback nil|fun(err: nil|string) M.render_buffer_async = function(bufnr, opts, callback) + vim.b[bufnr].oil_ready = false opts = vim.tbl_deep_extend("keep", opts or {}, { refetch = true, })