Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lua/FTerm/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ end
---Term:remember_cursor stores the last cursor position and window
---@return Term
function Term:remember_cursor()
self.last_tab = A.nvim_get_current_tabpage()
self.last_win = A.nvim_get_current_win()
self.prev_win = fn.winnr('#')
self.last_pos = A.nvim_win_get_cursor(self.last_win)
Expand All @@ -67,10 +68,16 @@ function Term:restore_cursor()
end

if U.is_win_valid(self.last_win) then
A.nvim_set_current_win(self.last_win)
-- Only switch to last window if we are on the same tabpage.
-- Otherwise it is annoying to return to return to the another
-- tabpage only because of closing the terminal.
if self.last_tab == A.nvim_get_current_tabpage() then
A.nvim_set_current_win(self.last_win)
end
A.nvim_win_set_cursor(self.last_win, self.last_pos)
end

self.last_tab = nil
self.last_win = nil
self.prev_win = nil
self.last_pos = nil
Expand Down