From a4a7d49bed41d907ed2ce3912f64248351ec93e3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 17 Oct 2021 12:47:13 +0530 Subject: [PATCH] A new swap_with_window mappable action Allows visual selection of a window to swap with the current window --- docs/basic.rst | 1 + docs/changelog.rst | 2 +- kitty/options/definition.py | 1 + kitty/options/types.py | 2 ++ kitty/tabs.py | 9 ++++++++- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/basic.rst b/docs/basic.rst index 2d5da6500..58083ca94 100644 --- a/docs/basic.rst +++ b/docs/basic.rst @@ -58,6 +58,7 @@ Move window forward :sc:`move_window_forward` Move window backward :sc:`move_window_backward` Move window to top :sc:`move_window_to_top` Visually focus window :sc:`focus_visible_window` +Visually swap window :sc:`swap_with_window` Focus specific window :sc:`first_window`, :sc:`second_window` ... :sc:`tenth_window` (also :kbd:`⌘+1`, :kbd:`⌘+2` ... :kbd:`⌘+9` on macOS) (clockwise from the top-left) diff --git a/docs/changelog.rst b/docs/changelog.rst index c5c27b086..482edf874 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -32,7 +32,7 @@ To update |kitty|, :doc:`follow the instructions `. the request by default instead of denying by default. See :opt:`clipboard_control` for details (:iss:`4022`) -- A new mappable action ``select_window_in_tab`` to select a window in the current tab to switch to, by window title +- A new mappable action ``swap_with_window`` to swap the current window with another window in the tab, visually - A new option :opt:`bell_path` to specify the path to a sound file to use as the bell sound diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 013d07d10..25753bd96 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -3152,6 +3152,7 @@ map('Tenth window', ) map('Visually select focus window', 'focus_visible_window kitty_mod+f7 focus_visible_window') +map('Visually swap window with another', 'swap_with_window kitty_mod+f8 swap_with_window') egr() # }}} diff --git a/kitty/options/types.py b/kitty/options/types.py index 2cbf58f63..0d659dd72 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -769,6 +769,8 @@ defaults.map = [ KeyDefinition(False, KeyAction('tenth_window'), 1024, False, 48, ()), # focus_visible_window KeyDefinition(False, KeyAction('focus_visible_window'), 1024, False, 57370, ()), + # swap_with_window + KeyDefinition(False, KeyAction('swap_with_window'), 1024, False, 57371, ()), # next_tab KeyDefinition(False, KeyAction('next_tab'), 1024, False, 57351, ()), # next_tab diff --git a/kitty/tabs.py b/kitty/tabs.py index b719a5072..e56471a8a 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -572,7 +572,8 @@ class Tab: # {{{ if group is not None: w = self.active_window if w is not None and w.id != window_id: - self.current_layout.move_window_to_group(self.windows, group.id) + if self.current_layout.move_window_to_group(self.windows, group.id): + self.relayout() @ac('win', ''' Focus a visible window by pressing the number of the window. Window numbers are displayed @@ -584,6 +585,12 @@ class Tab: # {{{ get_boss().visual_window_select_action(self, callback, 'Choose window to switch to') + @ac('win', 'Swap the current window with another window in the current tab, selected visually') + def swap_with_window(self) -> None: + def callback(tab: Tab, window: Window) -> None: + tab.swap_active_window_with(window.id) + get_boss().visual_window_select_action(self, callback, 'Choose window to swap with') + @ac('win', 'Move active window to the top (make it the first window)') def move_window_to_top(self) -> None: n = self.windows.active_group_idx