From 17ff317d3092b3c7f18c2c46569a39457abb4ba6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 28 Jul 2021 21:50:09 +0530 Subject: [PATCH] Allow specifying additional targets for detach_window --- docs/basic.rst | 4 ++++ docs/changelog.rst | 3 +++ kitty/boss.py | 12 ++++++++---- kitty/options/utils.py | 2 +- kitty/tabs.py | 12 ++++++++++++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/basic.rst b/docs/basic.rst index c7010306c..1ad34c8dd 100644 --- a/docs/basic.rst +++ b/docs/basic.rst @@ -83,6 +83,10 @@ move it to another tab or another OS window:: map ctrl+f2 detach_window # moves the window into a new Tab map ctrl+f3 detach_window new-tab + # moves the window into the previously active tab + map ctrl+f3 detach_window tab-prev + # moves the window into the tab at the left of the active tab + map ctrl+f3 detach_window tab-left # asks which tab to move the window into map ctrl+f4 detach_window ask diff --git a/docs/changelog.rst b/docs/changelog.rst index bedf80e48..0a9340929 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,6 +15,9 @@ To update |kitty|, :doc:`follow the instructions `. - macOS: Fix an error on Apple silicon when enumerating monitors (:pull:`3875`) +- Allow specifying the previously active tab or the tab to the left/right of + the active tab + 0.22.0 [2021-07-26] ---------------------- diff --git a/kitty/boss.py b/kitty/boss.py index a1aa3bbad..39cc4fc6d 100755 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1691,14 +1691,17 @@ class Boss: target_tab = tm.new_tab(empty_tab=True) else: target_os_window_id = target_os_window_id or current_os_window() - if target_tab_id == 'new': + if isinstance(target_tab_id, str): if not isinstance(target_os_window_id, int): q = self.active_tab_manager assert q is not None tm = q else: tm = self.os_window_map[target_os_window_id] - target_tab = tm.new_tab(empty_tab=True) + if target_tab_id == 'new': + target_tab = tm.new_tab(empty_tab=True) + else: + target_tab = tm.tab_at_location(target_tab_id) or tm.new_tab(empty_tab=True) else: for tab in self.all_tabs: if tab.id == target_tab_id: @@ -1766,8 +1769,9 @@ class Boss: ''' if not args or args[0] == 'new': return self._move_window_to(target_os_window_id='new') - if args[0] == 'new-tab': - return self._move_window_to(target_tab_id='new') + if args[0] in ('new-tab', 'tab-prev', 'tab-left', 'tab-right'): + where = 'new' if args[0] == 'new-tab' else args[0][4:] + return self._move_window_to(target_tab_id=where) title = 'Choose a tab to move the window to' lines = [title, ''] fmt = ': {1}' diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 65b1dc70c..bf55a0a58 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -102,7 +102,7 @@ def goto_tab_parse(func: str, rest: str) -> FuncArgsType: @func_with_args('detach_window') def detach_window_parse(func: str, rest: str) -> FuncArgsType: - if rest not in ('new', 'new-tab', 'ask'): + if rest not in ('new', 'new-tab', 'ask', 'tab-prev', 'tab-left', 'tab-right'): log_error('Ignoring invalid detach_window argument: {}'.format(rest)) rest = 'new' return func, (rest,) diff --git a/kitty/tabs.py b/kitty/tabs.py index aaed8ca0d..d45999f0a 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -720,6 +720,18 @@ class TabManager: # {{{ if len(self.tabs) > 1: self.set_active_tab_idx((self.active_tab_idx + len(self.tabs) + delta) % len(self.tabs)) + def tab_at_location(self, loc: str) -> Optional[Tab]: + if loc == 'prev': + if self.active_tab_history: + old_active_tab_id = self.active_tab_history[-1] + for idx, tab in enumerate(self.tabs): + if tab.id == old_active_tab_id: + return tab + elif loc in ('left', 'right'): + delta = -1 if loc == 'left' else 1 + idx = (len(self.tabs) + self.active_tab_idx + delta) % len(self.tabs) + return self.tabs[idx] + def goto_tab(self, tab_num: int) -> None: if tab_num >= len(self.tabs): tab_num = max(0, len(self.tabs) - 1)