From 93a281c7e3d1d6b63b63b4212c3ff7a28990f654 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 26 Mar 2020 22:05:00 +0530 Subject: [PATCH] Add a new mappable action ``close_other_windows_in_tab`` to close all but the active window Fixes #2484 --- docs/changelog.rst | 3 +++ docs/index.rst | 6 ++++++ kitty/tabs.py | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5e5a70ad6..475fe6615 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -10,6 +10,9 @@ To update |kitty|, :doc:`follow the instructions `. - Fix a regression in 0.17 that broke drawing of borders with non-minimal borders (:iss:`2474`) +- Add a new mappable action ``close_other_windows_in_tab`` to close all but the + active window (:iss:`2484`) + - Hints kitten: Adjust the default regex used to detect line numbers to handle line+column numbers (:iss:`2268`) diff --git a/docs/index.rst b/docs/index.rst index ebb445833..3521c2d53 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -192,6 +192,12 @@ Similarly, you can detach the current tab, with:: # asks which OS Window to move the tab into map ctrl+f4 detach_tab ask +Finally, you can define a shortcut to close all windows in a tab other than +the currently active window:: + + map f9 close_other_windows_in_tab + + Other keyboard shortcuts ---------------------------------- diff --git a/kitty/tabs.py b/kitty/tabs.py index 2fe7a2fa2..797f5e346 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -384,6 +384,13 @@ class Tab: # {{{ if self.windows: self.remove_window(self.windows[self.active_window_idx]) + def close_other_windows_in_tab(self) -> None: + if len(self.windows) > 1: + active_window = self.windows[self.active_window_idx] + for window in tuple(self.windows): + if window is not active_window: + self.remove_window(window) + def previous_active_window_idx(self, num: int) -> Optional[int]: try: old_window_id = self.active_window_history[-num]