From 214dc73c526616273422f7fd646f37389acf3ad3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 12 Aug 2025 18:45:23 +0530 Subject: [PATCH] When serializing windows in a tab keep the window order This is needed because layouts other than split use the window order to position windows. Maybe should serialize active history in layout state, but I dont think it's that important. --- kitty/tabs.py | 8 ++++++-- kitty/window_list.py | 6 ------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/kitty/tabs.py b/kitty/tabs.py index 9735cc419..c2fd0a71b 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -292,13 +292,17 @@ class Tab: # {{{ def serialize_state_as_session(self) -> list[str]: import shlex launch_cmds = [] - for g in self.windows.iter_groups_in_activation_order(): + active_idx = self.windows.active_group_idx + for i, g in enumerate(self.windows.iter_all_layoutable_groups()): gw: list[str] = [] for window in g: lc = window.as_launch_command(is_overlay=bool(gw)) if lc: gw.append(shlex.join(lc)) - launch_cmds.extend(gw) + if gw: + launch_cmds.extend(gw) + if i == active_idx: + launch_cmds.append('focus') if launch_cmds: return [ f'new_tab {self.name}'.rstrip(), diff --git a/kitty/window_list.py b/kitty/window_list.py index 9cba0e185..0fba377c1 100644 --- a/kitty/window_list.py +++ b/kitty/window_list.py @@ -333,12 +333,6 @@ class WindowList: return self.set_active_group_idx(len(self.groups) - 1, notify=notify) - def iter_groups_in_activation_order(self) -> Iterator[WindowGroup]: - imap = {gid: i for i, gid in enumerate(self.active_group_history)} - def skey(g: WindowGroup) -> int: - return imap.get(g.id, -1) - yield from sorted(self.groups, key=skey) - @property def num_groups(self) -> int: return len(self.groups)