diff --git a/doc/upstream.md b/doc/upstream.md index 327d32f..a26b7a9 100644 --- a/doc/upstream.md +++ b/doc/upstream.md @@ -72,13 +72,13 @@ issues against this fork. | [#392](https://github.com/stevearc/oil.nvim/issues/392) | Option to skip delete prompt | fixed | | [#393](https://github.com/stevearc/oil.nvim/issues/393) | Auto-save on select | fixed | | [#396](https://github.com/stevearc/oil.nvim/issues/396) | Customize preview content | not actionable — out of scope, preview is a normal buffer; use `BufReadCmd` autocmds for custom renderers | -| [#399](https://github.com/stevearc/oil.nvim/issues/399) | Open file without closing Oil | open | +| [#399](https://github.com/stevearc/oil.nvim/issues/399) | Open file without closing Oil | fixed ([#159](https://github.com/barrettruth/canola.nvim/pull/159)) | | [#404](https://github.com/stevearc/oil.nvim/issues/404) | Restricted UNC paths | not actionable — Windows-only | | [#416](https://github.com/stevearc/oil.nvim/issues/416) | Cannot remap key to open split | fixed — cherry-picked ([#725](https://github.com/stevearc/oil.nvim/pull/725)) | | [#431](https://github.com/stevearc/oil.nvim/issues/431) | More SSH adapter documentation | duplicate of [#525](https://github.com/stevearc/oil.nvim/issues/525) | | [#435](https://github.com/stevearc/oil.nvim/issues/435) | Error previewing with semantic tokens LSP | fixed — cherry-picked ([#467](https://github.com/stevearc/oil.nvim/pull/467)) | | [#436](https://github.com/stevearc/oil.nvim/issues/436) | Owner and group columns | consolidated into [#126](https://github.com/barrettruth/canola.nvim/issues/126) | -| [#444](https://github.com/stevearc/oil.nvim/issues/444) | Opening behaviour customization | not actionable — existing API covers all use cases, reporter satisfied | +| [#444](https://github.com/stevearc/oil.nvim/issues/444) | Opening behaviour customization | not actionable — existing API covers all use cases, reporter satisfied | | [#446](https://github.com/stevearc/oil.nvim/issues/446) | Executable highlighting | cherry-picked ([#698](https://github.com/stevearc/oil.nvim/pull/698)) | | [#449](https://github.com/stevearc/oil.nvim/issues/449) | Renaming TypeScript files stopped working | not actionable — config issue, increase `lsp_file_methods.timeout_ms` | | [#450](https://github.com/stevearc/oil.nvim/issues/450) | Highlight opened file in directory listing | fixed — added `oil-recipe-highlight-opened-file` | diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 9adc5f5..f4c2211 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -292,9 +292,17 @@ M.open_float = function(dir, opts, cb) if util.is_floating_win() or vim.fn.win_gettype() == 'command' then return end - if vim.api.nvim_win_is_valid(winid) then - vim.api.nvim_win_close(winid, true) + if not vim.api.nvim_win_is_valid(winid) then + for _, id in ipairs(autocmds) do + vim.api.nvim_del_autocmd(id) + end + autocmds = {} + return end + if vim.w[winid].oil_keep_open then + return + end + vim.api.nvim_win_close(winid, true) for _, id in ipairs(autocmds) do vim.api.nvim_del_autocmd(id) end @@ -851,6 +859,8 @@ M.select = function(opts, callback) local prev_win = vim.api.nvim_get_current_win() local oil_bufnr = vim.api.nvim_get_current_buf() + local keep_float_open = util.is_floating_win() and opts.close == false + local float_win = keep_float_open and prev_win or nil -- Async iter over entries so we can normalize the url before opening local i = 1 @@ -868,8 +878,10 @@ M.select = function(opts, callback) return cb('Please save changes before entering new directory') end else - -- Close floating window before opening a file - if vim.w.is_oil_win then + local is_float = util.is_floating_win() + if is_float and opts.close == false then + vim.w.oil_keep_open = true + elseif vim.w.is_oil_win then M.close() end end @@ -892,10 +904,23 @@ M.select = function(opts, callback) vim.bo[filebufnr].buflisted = true end + if keep_float_open and not opts.tab then + local original_win = vim.w[float_win].oil_original_win + if original_win and vim.api.nvim_win_is_valid(original_win) then + vim.api.nvim_set_current_win(original_win) + else + for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do + if winid ~= float_win and not util.is_floating_win(winid) then + vim.api.nvim_set_current_win(winid) + break + end + end + end + end + local cmd = 'buffer' if opts.tab then vim.cmd.tabnew({ mods = mods }) - -- Make sure the new buffer from tabnew gets cleaned up vim.bo.bufhidden = 'wipe' elseif opts.split then cmd = 'sbuffer' @@ -934,6 +959,13 @@ M.select = function(opts, callback) end) end + if float_win and vim.api.nvim_win_is_valid(float_win) then + if opts.tab then + vim.api.nvim_set_current_tabpage(vim.api.nvim_win_get_tabpage(float_win)) + end + vim.api.nvim_set_current_win(float_win) + end + update_preview_window() finish()