Merge branch 'session-restore-tab-focus' of https://github.com/jackielii/kitty

This commit is contained in:
Kovid Goyal
2025-11-02 22:12:03 +05:30
2 changed files with 11 additions and 6 deletions

View File

@@ -1314,12 +1314,10 @@ class TabManager: # {{{
is_first: bool = False
) -> list[str]:
ans = []
hmap = {tab_id: i for i, tab_id in enumerate(self.active_tab_history)}
if (at := self.active_tab) is not None:
hmap[at.id] = len(self.active_tab_history) + 1
def skey(tab: Tab) -> int:
return hmap.get(tab.id, -1)
for tab in sorted(self, key=skey):
active_tab_index = -1
for i, tab in enumerate(self.tabs):
if tab is self.active_tab:
active_tab_index = i
ans.extend(tab.serialize_state_as_session(session_path, matched_windows, ser_opts))
if ans:
prefix = [] if is_first else ['', '', 'new_os_window']
@@ -1328,6 +1326,10 @@ class TabManager: # {{{
if self.wm_name and self.wm_name != appname:
prefix.append(f'os_window_name {self.wm_name}')
ans = prefix + ans
# Add focus_tab command to preserve the active tab
if active_tab_index >= 0:
ans.append('')
ans.append(f'focus_tab {active_tab_index}')
return ans
@property