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
commit 0c3566cb80
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 6 deletions

View file

@ -202,6 +202,9 @@ Detailed list of changes
- Add ``state:focused_os_window`` match query to select all windows in the
currently focused OS window (:ref:`search_syntax`)
- Session saving now automatically preserves which tab is active in each OS
window by adding a ``focus_tab`` command to saved session files
0.43.1 [2025-10-01]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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