From 780b4337e43df5d0fe664366c7304f0e50cb39f2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 11:18:13 +0000 Subject: [PATCH] Fix move_tab_forward/backward with tab_bar_filter When tab_bar_filter is used (e.g. with sessions), move_tab() was using self.active_tab_idx (index in the full tabs list) as an index into the filtered tabs list, causing incorrect behavior. Also fix the same bug in tab_at_location() for left/right locations. Fixes #9672 Fixes #9673 --- kitty/tabs.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/kitty/tabs.py b/kitty/tabs.py index 7174bd744..720f3f4cc 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -1337,8 +1337,13 @@ class TabManager: # {{{ return self.tab_for_id(self.active_tab_history[-1]) elif loc in ('left', 'right'): delta = -1 if loc == 'left' else 1 - idx = (len(tabs) + self.active_tab_idx + delta) % len(tabs) - return tabs[idx] + if (at := self.active_tab) is not None: + try: + active_idx = tabs.index(at) + except ValueError: + return None + idx = (len(tabs) + active_idx + delta) % len(tabs) + return tabs[idx] return None def goto_tab(self, tab_num: int) -> None: @@ -1439,8 +1444,14 @@ class TabManager: # {{{ def move_tab(self, delta: int = 1) -> None: tabs = tuple(self.tabs_to_be_shown_in_tab_bar) if len(tabs) > 1: - idx = self.active_tab_idx - new_active_tab = tabs[(idx + len(tabs) + delta) % len(tabs)] + if (at := self.active_tab) is None: + return + try: + filtered_idx = tabs.index(at) + except ValueError: + return + new_active_tab = tabs[(filtered_idx + len(tabs) + delta) % len(tabs)] + idx = self.tabs.index(at) nidx = self.tabs.index(new_active_tab) step = 1 if idx < nidx else -1 for i in range(idx, nidx, step):