add focus_tab to restore tab focus by default

This commit is contained in:
Jackie Li
2025-10-27 08:47:35 +00:00
parent 422bcf1328
commit dfbf5103c2
2 changed files with 11 additions and 1 deletions

View File

@@ -196,6 +196,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

@@ -1317,7 +1317,10 @@ class TabManager: # {{{
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(sorted(self, key=skey)):
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']
@@ -1326,6 +1329,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