From 96f3253e6de32ca90d1c2db9f3c37e783a60acb5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Jan 2020 20:17:17 +0530 Subject: [PATCH] goto_tab now maps numbers larger than the last tab to the last tab Fixes #2291 --- docs/changelog.rst | 3 +++ kitty/config_data.py | 3 ++- kitty/tabs.py | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 8b28af924..ecd5de429 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -33,6 +33,9 @@ To update |kitty|, :doc:`follow the instructions `. - Fix a segfault when using :option:`kitty --debug-config` with maps (:iss:`2270`) +- ``goto_tab`` now maps numbers larger than the last tab to the last tab + (:iss:`2291`) + 0.15.1 [2019-12-21] -------------------- diff --git a/kitty/config_data.py b/kitty/config_data.py index 0c5be0d3d..a3dbfeb2d 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -144,7 +144,8 @@ For example:: _('Tab management'), '', _('''\ You can also create shortcuts to go to specific tabs, with 1 being the first -tab, 2 the second tab and -1 being the previously active tab:: +tab, 2 the second tab and -1 being the previously active tab, and any number +larger than the last tab being the last tab:: map ctrl+alt+1 goto_tab 1 map ctrl+alt+2 goto_tab 2 diff --git a/kitty/tabs.py b/kitty/tabs.py index 07e55ecd9..d8ad5e43f 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -560,9 +560,11 @@ class TabManager: # {{{ self.set_active_tab_idx((self.active_tab_idx + len(self.tabs) + delta) % len(self.tabs)) def goto_tab(self, tab_num): - if 0 <= tab_num < len(self.tabs): + if tab_num >= len(self.tabs): + tab_num = max(0, len(self.tabs) - 1) + if tab_num >= 0: self.set_active_tab_idx(tab_num) - elif tab_num < 0: + else: try: old_active_tab_id = self.active_tab_history[tab_num] except IndexError: