From 522aa7805bf0b2057da27aa92a083e713313f07c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 1 Mar 2026 10:42:07 +0530 Subject: [PATCH] DRYer --- kitty/tabs.py | 12 +++--------- kitty/window_list.py | 3 +++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/kitty/tabs.py b/kitty/tabs.py index 8404e5286..7ba37c54a 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -815,15 +815,9 @@ class Tab: # {{{ overlay_for = window.id def set_active_window(self, x: Window | int, for_keep_focus: Window | None = None) -> None: - if isinstance(x, int): - for q in self: - if q.id == x: - x = q - break - else: - return - self.windows.set_active_window_group_for(x, for_keep_focus=for_keep_focus) - self.windows.move_window_to_top_of_group(x) + if (w := self.windows.window_for_id(x) if isinstance(x, int) else x) is not None: + self.windows.set_active_window_group_for(w, for_keep_focus=for_keep_focus) + self.windows.move_window_to_top_of_group(w) def get_nth_window(self, n: int) -> Window | None: if self.windows: diff --git a/kitty/window_list.py b/kitty/window_list.py index cde00d65e..5f7544505 100644 --- a/kitty/window_list.py +++ b/kitty/window_list.py @@ -340,6 +340,9 @@ class WindowList: def num_groups(self) -> int: return len(self.groups) + def window_for_id(self, x: int) -> WindowType | None: + return self.id_map.get(x) + def group_for_window(self, x: WindowOrId) -> WindowGroup | None: q = self.id_map[x] if isinstance(x, int) else x for g in self.groups: