Skip to content

Commit 1950040

Browse files
Copilotphanen
andauthored
fix: prevent terminal-job mode leak when closing fzf window
Agent-Logs-Url: https://github.com/ibhagwan/fzf-lua/sessions/f08cbff6-068d-454a-aaad-7d7cabece8fc Co-authored-by: phanen <91544758+phanen@users.noreply.github.com>
1 parent 83f7195 commit 1950040

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

lua/fzf-lua/win.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,11 +1175,13 @@ function FzfWin:close(fzf_bufnr, hide)
11751175
-- `fzf_win:close()` within `core.fzf()`. We need to avoid the close in this case.
11761176
if self.closing or (fzf_bufnr and fzf_bufnr ~= self.fzf_bufnr) then return end
11771177
self.closing = true -- prevents race condition
1178-
-- we restore normal mode before exiting fzf due toma neovim bug? whereas
1179-
-- switching from a term win to another term win preserves terminal mode
1180-
-- even if the target window was in normal terminal mode (#2054 #2419)
1178+
-- restore normal mode before exiting fzf due to a neovim bug where
1179+
-- switching from a terminal window to another terminal window may preserve
1180+
-- terminal-job mode, causing the target terminal to close on next keypress
1181+
-- if its job already exited (#2054 #2419 #2681)
11811182
local ctx = utils.__CTX() or {}
1182-
if ctx.mode == "nt" then vim.cmd "stopinsert" end
1183+
local mode = vim.api.nvim_get_mode().mode
1184+
if mode == "t" or mode == "nt" then vim.cmd "stopinsert" end
11831185
if self.fzf_winid and api.nvim_win_is_valid(self.fzf_winid) then
11841186
-- restore the original last window
11851187
restore_lastwin(ctx.winid, ctx.last_winid)

0 commit comments

Comments
 (0)