From 87eff1a57685eb9c8804824e677c7fb0014656ce Mon Sep 17 00:00:00 2001 From: bhagwan Date: Mon, 6 Jan 2025 20:07:53 -0800 Subject: [PATCH] fix(actions): do not reload curbuf on splits (#1677) --- lua/fzf-lua/actions.lua | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lua/fzf-lua/actions.lua b/lua/fzf-lua/actions.lua index 4fe16fc8..6214afc0 100644 --- a/lua/fzf-lua/actions.lua +++ b/lua/fzf-lua/actions.lua @@ -144,17 +144,25 @@ M.vimcmd_entry = function(_vimcmd, selected, opts, pcall_vimcmd) if not path.is_absolute(fullpath) then fullpath = path.join({ opts.cwd or opts._cwd or uv.cwd(), fullpath }) end - -- Adjust "" edits based on entry being buffer or filename - local vimcmd = _vimcmd:gsub("", entry.bufnr and entry.bufname and "b" or "e") - -- Do not execute "edit" commands if we already have the same buffer/file open - -- or if we are dealing with a URI as it's open with `vim.lsp.util.show_document` -- opts.__CTX isn't guaranteed by API users (#1414) local CTX = opts.__CTX or utils.CTX() - if vimcmd == "e" and (entry.uri or path.equals(fullpath, CTX.bname)) - or vimcmd == "b" and entry.bufnr and entry.bufnr == CTX.bufnr - then - vimcmd = nil - end + local target_equals_current = entry.bufnr and entry.bufnr == CTX.bufnr + or path.equals(fullpath, CTX.bname) + local vimcmd = (function() + -- Do not execute "edit" commands if we already have the same buffer/file open + -- or if we are dealing with a URI as it's open with `vim.lsp.util.show_document` + if _vimcmd == "" and (entry.uri or target_equals_current) then + return nil + end + -- Same buffer splits and URI entries only execute the split cmd + -- after a split we land in the same buffer, remove the piped edit + -- e.g. "vsplit | e" -> "vsplit" (#1677) + if _vimcmd:match("| ") and (entry.uri or target_equals_current) then + return _vimcmd:gsub("| ", "") + end + -- Replace "" based on entry being buffer or filename + return _vimcmd:gsub("", entry.bufnr and entry.bufname and "b" or "e") + end)() -- ":b" and ":e" commands replace the current buffer local will_replace_curbuf = vimcmd == "e" or vimcmd == "b" if will_replace_curbuf @@ -187,11 +195,8 @@ M.vimcmd_entry = function(_vimcmd, selected, opts, pcall_vimcmd) if entry.terminal and vimcmd == "bd" then vimcmd = vimcmd .. "!" end - if entry.uri then - -- URI entries only execute new buffers (new|vnew|tabnew) - -- remove the piped cmd, "vsplit | e" -> "vsplit" (#1677) - vimcmd = vimcmd:match("[^|]+") - else + -- URI entries only execute new buffers (new|vnew|tabnew) + if not entry.uri then -- Force full paths when `autochdir=true` (#882) vimcmd = string.format("%s %s", vimcmd, (function() -- `:argdel|:argadd` uses only paths