From 3637e31ca3aa466a7e1ef0c56e5eb2411c3a7dac Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 8 Jan 2026 20:43:38 +0530 Subject: [PATCH] Fix goto_session not respecting the focus_tab session directive when creating a session in an existing OS window Fixes #9366 --- docs/changelog.rst | 3 +++ kitty/tabs.py | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 99957ddf9..075f4bb2e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -176,6 +176,9 @@ Detailed list of changes - Fix a regression in the previous release that caused moving between neighbors in the vertical and horizontal layouts to go in the opposite direction (:iss:`9355`) +- Fix :ac:`goto_session` not respecting the focus_tab session directive when + creating a session in an existing OS window (:iss:`9366`) + 0.45.0 [2025-12-24] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/tabs.py b/kitty/tabs.py index 1da86e36b..950bb35f8 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -1075,9 +1075,11 @@ class TabManager: # {{{ def add_tabs_from_session(self, session: SessionType, session_name: str = '') -> None: active_tab = self.active_tab + added_tabs = [] for i, t in enumerate(session.tabs): tab = Tab(self, session_tab=t, session_name=session_name or self.created_in_session_name) self._add_tab(tab) + added_tabs.append(tab) if i == session.active_tab_idx: active_tab = tab @@ -1088,8 +1090,8 @@ class TabManager: # {{{ try: idx = int(spec) # Clamp to valid range - idx = max(0, min(idx, len(self.tabs) - 1)) - active_tab = self.tabs[idx] + idx = max(0, min(idx, len(added_tabs) - 1)) + active_tab = added_tabs[idx] except ValueError: # Not a plain number, treat as match expression from .fast_data_types import get_boss @@ -1101,6 +1103,11 @@ class TabManager: # {{{ if active_tab is not None: idx = self.tabs.index(active_tab) self._set_active_tab(idx) + # We need to update last_focused_at so that switch_to_session is + # called after the session is created respects the result of + # focus_tab. + if (at := self.active_tab) and (w := at.active_window): + w.last_focused_at = monotonic() @property def active_tab_idx(self) -> int: