diff --git a/docs/changelog.rst b/docs/changelog.rst index 55d8f0be4..6da059bd4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -79,6 +79,8 @@ Detailed list of changes - Linux: Fix a regression in 0.36.0 that caused font features defined via fontconfig to be ignored (:iss:`7773`) +- :ac:`goto_tab`: Allow numbers less than ``-1`` to go to the Nth previously active tab + 0.36.1 [2024-08-24] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 5eafafa42..0ef2841c2 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -3968,8 +3968,9 @@ map('Set tab title', egr(''' You can also create shortcuts to go to specific :term:`tabs `, with :code:`1` being the first tab, :code:`2` the second tab and :code:`-1` being the -previously active tab, and any number larger than the last tab being the last -tab:: +previously active tab, :code:`-2` being the tab active before the previously active tab and so on. +Any number larger than the number of tabs goes to the last tab and any number less +than the number of previously used tabs in the history goes to the oldest previously used tab in the history:: map ctrl+alt+1 goto_tab 1 map ctrl+alt+2 goto_tab 2 diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 49c8517bb..2a23447d3 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -145,8 +145,10 @@ def open_url_parse(func: str, rest: str) -> FuncArgsType: @func_with_args('goto_tab') def goto_tab_parse(func: str, rest: str) -> FuncArgsType: - args = (max(0, int(rest)), ) - return func, args + n = int(rest) + if n < 0: + n += 1 # goto_tab subtracts 1 from its argument, this maps both zero and -1 to previous tab for backwards compat. + return func, (n,) @func_with_args('detach_window') diff --git a/kitty/tabs.py b/kitty/tabs.py index e781cb119..3629ac6e8 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -1034,11 +1034,11 @@ class TabManager: # {{{ tab_num = max(0, len(self.tabs) - 1) if tab_num >= 0: self.set_active_tab_idx(tab_num) - else: + elif self.active_tab_history: try: old_active_tab_id = self.active_tab_history[tab_num] except IndexError: - return + old_active_tab_id = self.active_tab_history[0] for idx, tab in enumerate(self.tabs): if tab.id == old_active_tab_id: self.set_active_tab_idx(idx)