Skip to content

Commit 3aa9530

Browse files
committed
fixup! fix: use :startinsert instead of feedkeys to switch to terminal mode
1 parent 9cf367c commit 3aa9530

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lua/fzf-lua/fzf.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
222222
vim.keymap.set("t", "<C-c>", "<Esc>", { buffer = 0 })
223223
end
224224

225-
vim.api.nvim_create_autocmd("TermOpen", { once = true, buffer = 0, command = "startinsert" })
225+
local fzf_bufnr = vim.api.nvim_get_current_buf()
226+
vim.api.nvim_create_autocmd("TermOpen",
227+
{ once = true, buffer = 0, callback = function() utils.ensure_startinsert(fzf_bufnr) end })
226228
-- A more robust way of entering TERMINAL mode "t". We had quite a few issues
227229
-- sending `feedkeys|startinsert` after the term job is started, this approach
228230
-- seems more consistent as it triggers when entering terminal normal mode "nt"
@@ -335,7 +337,6 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
335337
if not opts.is_fzf_tmux then
336338
vim.bo.filetype = "fzf"
337339
-- See note in "ModeChanged" above
338-
-- utils.ensure_startinsert()
339340
end
340341

341342
return coroutine.yield()

lua/fzf-lua/utils.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,10 +1317,11 @@ function M.setmetatable__gc(t, mt)
13171317
return setmetatable(t, mt)
13181318
end
13191319

1320+
---@param bufnr
13201321
---@param retry integer?
13211322
---@param timeout integer?
1322-
function M.ensure_startinsert(retry, timeout)
1323-
local bufnr = vim.api.nvim_get_current_buf()
1323+
function M.ensure_startinsert(bufnr, retry, timeout)
1324+
bufnr = bufnr or vim.api.nvim_get_current_buf()
13241325
local function ensure_startinsert(_retry, _timeout)
13251326
-- abort for some reason we switch to another buffer
13261327
if vim.api.nvim_get_current_buf() ~= bufnr then return end

0 commit comments

Comments
 (0)