diff --git a/lua/fzf-lua/actions.lua b/lua/fzf-lua/actions.lua index 2881ec0..7254381 100644 --- a/lua/fzf-lua/actions.lua +++ b/lua/fzf-lua/actions.lua @@ -310,24 +310,24 @@ M.ensure_insert_mode = function() -- mode was introduced along with the 'ModeChanged' event -- https://github.com/neovim/neovim/pull/15878 -- https://github.com/neovim/neovim/pull/15840 - local has_mode_nt = not vim.tbl_isempty( - vim.fn.getcompletion('ModeChanged', 'event')) - or vim.fn.has('nvim-0.6') == 1 - if has_mode_nt then - local mode = vim.api.nvim_get_mode() - local wininfo = vim.fn.getwininfo(vim.api.nvim_get_current_win())[1] - if vim.bo.ft == 'fzf' - and wininfo.terminal == 1 - and mode and mode.mode == 't' then - vim.cmd[[noautocmd lua vim.api.nvim_feedkeys('i', 'n', true)]] - end - end + -- local has_mode_nt = not vim.tbl_isempty( + -- vim.fn.getcompletion('ModeChanged', 'event')) + -- or vim.fn.has('nvim-0.6') == 1 + -- if has_mode_nt then + -- local mode = vim.api.nvim_get_mode() + -- local wininfo = vim.fn.getwininfo(vim.api.nvim_get_current_win())[1] + -- if vim.bo.ft == 'fzf' + -- and wininfo.terminal == 1 + -- and mode and mode.mode == 't' then + -- vim.cmd[[noautocmd lua vim.api.nvim_feedkeys('i', 'n', true)]] + -- end + -- end + utils.warn("calling 'ensure_insert_mode' is no longer required and can be safely omitted.") end M.run_builtin = function(selected) local method = selected[1] vim.cmd(string.format("lua require'fzf-lua'.%s()", method)) - M.ensure_insert_mode() end M.ex_run = function(selected) @@ -588,10 +588,8 @@ M.grep_lgrep = function(_, opts) if opts.__FNCREF__ then opts.__MODULE__.grep(o) - -- require'fzf-lua.actions'.ensure_insert_mode() else opts.__MODULE__.live_grep(o) - -- require'fzf-lua.actions'.ensure_insert_mode() end end diff --git a/lua/fzf-lua/fzf.lua b/lua/fzf-lua/fzf.lua index 0a3b150..a89e9bf 100644 --- a/lua/fzf-lua/fzf.lua +++ b/lua/fzf-lua/fzf.lua @@ -147,7 +147,29 @@ function M.raw_fzf(contents, fzf_cli_args, opts) end }) vim.cmd[[set ft=fzf]] - vim.cmd[[startinsert]] + + -- terminal behavior seem to have changed after the introduction + -- of 'nt' mode (terminal-normal mode) which is included in 0.6 + -- https://github.com/neovim/neovim/pull/15878 + -- preferably I'd like to check if the vim patch is included using + -- vim.fn.has('patch-8.2.3461') + -- but this doesn't work for vim patches > 8.1 as explained in: + -- https://github.com/neovim/neovim/issues/9635 + -- however, since this patch was included in 0.6 we can test + -- for neovim version 0.6 + -- beats me why 'nvim_get_mode().mode' still returns 'nt' even + -- after we're clearly in insert mode or why `:startinsert` + -- won't change the mode from 'nt' to 't' so we use feedkeys() + -- instead. + -- this "retires" 'actions.ensure_insert_mode' and solves the + -- issue of calling an fzf-lua mapping from insert mode (#429) + if vim.fn.has('nvim-0.6') == 1 then + vim.cmd([[noautocmd lua vim.api.nvim_feedkeys(]] + .. [[vim.api.nvim_replace_termcodes("i", true, false, true)]] + .. [[, 'n', true)]]) + else + vim.cmd[[startinsert]] + end if not contents or type(contents) == "string" then goto wait_for_fzf diff --git a/lua/fzf-lua/providers/dap.lua b/lua/fzf-lua/providers/dap.lua index 852dc77..96e2114 100644 --- a/lua/fzf-lua/providers/dap.lua +++ b/lua/fzf-lua/providers/dap.lua @@ -37,10 +37,6 @@ M.commands = function(opts) ["default"] = opts.actions and opts.actions.default or function(selected, _) _dap[selected[1]]() - if require'fzf-lua.providers.ui_select'.is_registered() then - -- opening an fzf-lua win from another requires this - actions.ensure_insert_mode() - end end, }