fix: alternate buffer preservation (#43)

This commit is contained in:
Steven Arcangeli 2023-01-20 02:56:57 -08:00
parent a60639db35
commit 4e853eabcb
3 changed files with 27 additions and 2 deletions

View file

@ -660,7 +660,8 @@ M.setup = function(opts)
group = aug,
pattern = "*",
callback = function()
if vim.bo.filetype ~= "oil" then
local util = require("oil.util")
if not util.is_oil_bufnr(0) then
vim.api.nvim_win_set_var(0, "oil_original_buffer", vim.api.nvim_get_current_buf())
vim.api.nvim_win_set_var(0, "oil_original_alternate", vim.fn.bufnr("#"))
end
@ -719,7 +720,8 @@ M.setup = function(opts)
pattern = "*",
nested = true,
callback = function(params)
if vim.bo[params.buf].filetype ~= "oil" or vim.w.oil_did_enter then
local util = require("oil.util")
if not util.is_oil_bufnr(params.buf) or vim.w.oil_did_enter then
return
end
-- This new window is a split off of an oil window. We need to transfer the window

View file

@ -489,6 +489,16 @@ M.run_in_fullscreen_win = function(bufnr, callback)
vim.cmd.close({ count = winnr, mods = { noautocmd = true, emsg_silent = true } })
end
---@param bufnr integer
---@return boolean
M.is_oil_bufnr = function(bufnr)
if vim.bo[bufnr].filetype == "oil" then
return true
end
local scheme = M.parse_url(vim.api.nvim_buf_get_name(bufnr))
return config.adapters[scheme] or config.adapter_aliases[scheme]
end
---This is a hack so we don't end up in insert mode after starting a task
---@param prev_mode string The vim mode we were in before opening a terminal
M.hack_around_termopen_autocmd = function(prev_mode)