File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ local ctx
1111--- @field bufnr integer
1212--- @field bname string
1313--- @field winid integer
14+ --- @field last_winid integer
1415--- @field alt_bufnr integer
1516--- @field tabnr integer
1617--- @field tabh integer
@@ -51,6 +52,7 @@ M.refresh = function(opts)
5152 bufnr = vim .api .nvim_get_current_buf (),
5253 bname = vim .api .nvim_buf_get_name (0 ),
5354 winid = vim .api .nvim_get_current_win (),
55+ last_winid = vim .fn .win_getid (vim .fn .winnr (" #" )),
5456 alt_bufnr = vim .fn .bufnr (" #" ),
5557 tabnr = vim .fn .tabpagenr (),
5658 tabh = vim .api .nvim_win_get_tabpage (0 ),
Original file line number Diff line number Diff line change @@ -1140,6 +1140,17 @@ function FzfWin:close_preview(do_not_clear_cache)
11401140 self .preview_winid = nil
11411141end
11421142
1143+ --- @param winid ? integer
1144+ --- @param last_winid ? integer
1145+ local restore_lastwin = function (winid , last_winid )
1146+ if winid and last_winid and api .nvim_win_is_valid (last_winid ) then
1147+ utils .eventignore (function ()
1148+ api .nvim_set_current_win (last_winid )
1149+ api .nvim_set_current_win (winid )
1150+ end )
1151+ end
1152+ end
1153+
11431154--- @param buf ? integer
11441155local restore_altbuf = function (buf )
11451156 if buf and api .nvim_buf_is_valid (buf ) then
@@ -1166,6 +1177,8 @@ function FzfWin:close(fzf_bufnr, hide)
11661177 local ctx = utils .__CTX () or {}
11671178 if ctx .mode == " nt" then vim .cmd " stopinsert" end
11681179 if self .fzf_winid and api .nvim_win_is_valid (self .fzf_winid ) then
1180+ -- restore the original last window
1181+ restore_lastwin (ctx .winid , ctx .last_winid )
11691182 -- run in a pcall due to potential errors while closing the window
11701183 -- Vim(lua):E5108: Error executing lua
11711184 -- experienced while accessing 'vim.b[]' from my statusline code
You can’t perform that action at this time.
0 commit comments