Skip to content

Commit bd281b9

Browse files
vanhtuan0409claude
authored andcommitted
fix(actions): pass nil to can_replace_buf instead of 0
In Lua, 0 is truthy so `buf = buf or nvim_get_current_buf()` never falls back, and `getbufinfo(0)` returns an empty table where `changed` is nil. Since `nil ~= 0` is true, `buffer_is_dirty` always reports dirty, causing `can_replace_buf` to always return false when `hidden=false` — breaking file_edit for every selection. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 26dd5e3 commit bd281b9

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

lua/fzf-lua/actions.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ end
192192

193193
---@return boolean
194194
local can_replace_buf = function(buf)
195-
buf = buf or vim.api.nvim_get_current_buf()
196195
return vim.o.hidden
197196
or vim.o.confirm
198197
or vim.o.autowriteall
@@ -239,7 +238,7 @@ M.vimcmd_entry = function(vimcmd, selected, opts, bufedit)
239238
end
240239
if layoutcmd then
241240
vim.cmd(layoutcmd)
242-
elseif not is_curbuf(entry.bufnr, fullpath) and not can_replace_buf(0) then
241+
elseif not is_curbuf(entry.bufnr, fullpath) and not can_replace_buf() then
243242
return utils.warn("Unable to add buffer %s", fullpath)
244243
end
245244
-- NOTE: URI entries only execute new buffers (new|vnew|tabnew)

lua/fzf-lua/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ end
11161116
---@param only_if_last_buffer? boolean
11171117
---@return boolean
11181118
function M.buffer_is_dirty(bufnr, warn, only_if_last_buffer)
1119-
bufnr = bufnr or vim.api.nvim_get_current_buf()
1119+
bufnr = (bufnr == nil or bufnr == 0) and vim.api.nvim_get_current_buf() or bufnr
11201120
local info = bufnr and M.getbufinfo(bufnr)
11211121
if info and info.changed ~= 0 then
11221122
if only_if_last_buffer and 1 < #vim.fn.win_findbuf(bufnr) then

0 commit comments

Comments
 (0)