From 34de072a108141658c8297c10bff9636d8974303 Mon Sep 17 00:00:00 2001 From: David Martin Date: Wed, 3 Apr 2019 19:27:04 +1100 Subject: [PATCH] Add option to disable switching to the previous tab when closing the current one. When setting tab_bar_switch_to_previous_when_closing_current_tab kitty will now switch to the left tab instead of the previously active one when the currently active tab is closed. This makes the closing of tabs a bit more predictable. Note that we are not touching the handling of the active_tab_history at all. I was considering it, but we want to keep track of it in any case to keep the 'switch to previous tab' shortcut working. --- kitty/config_data.py | 5 +++++ kitty/tabs.py | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/kitty/config_data.py b/kitty/config_data.py index 198dbf277..faee28c30 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -631,6 +631,11 @@ o('tab_bar_min_tabs', 2, option_type=lambda x: max(1, positive_int(x)), long_tex The minimum number of tabs that must exist before the tab bar is shown ''')) +o('tab_bar_switch_to_previous_when_closing_current_tab', True, long_text=_(''' +Switch to the previously active tab when the current tab is closed. The default is yes. +If no, the tab to the left of the current tab is selected when the current tab is closed. +''')) + def tab_fade(x): return tuple(map(unit_float, x.split())) diff --git a/kitty/tabs.py b/kitty/tabs.py index 8b7d5ca39..a63ed86d7 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -562,6 +562,16 @@ class TabManager: # {{{ break if next_active_tab < 0: next_active_tab = max(0, min(self.active_tab_idx, len(self.tabs) - 1)) + + if not self.opts.tab_bar_switch_to_previous_when_closing_current_tab: + # When we do not switch to the previously active tab, we set the next left tab + # as active. Unless there are no further tabs on the left, in which case + # we select the new leftmost tab. + if self.active_tab_idx > 0: + next_active_tab = self.active_tab_idx - 1 + else: + next_active_tab = 0 + self._set_active_tab(next_active_tab) self.mark_tab_bar_dirty() tab.destroy()