From a9556aa872215f5956062f24064ade55cf2baeb9 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Thu, 27 Apr 2023 07:30:48 -0700 Subject: [PATCH] fix: guard against invalid buffer (#90) --- lua/oil/init.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 437f9c0..732845c 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -667,6 +667,10 @@ local function load_oil_buffer(bufnr) loading.set_loading(bufnr, true) local winid = vim.api.nvim_get_current_win() local function finish(new_url) + -- If the buffer was deleted while we were normalizing the name, early return + if not vim.api.nvim_buf_is_valid(bufnr) then + return + end -- Since this was async, we may have left the window with this buffer. People often write -- BufReadPre/Post autocmds with the expectation that the current window is the one that -- contains the buffer. Let's then do our best to make sure that that assumption isn't violated.