Add option :option:kitten @ detach-window --stay-in-tab to keep focus in the currently active tab when moving windows

Fixes #7468
This commit is contained in:
Kovid Goyal
2024-05-23 21:45:30 +05:30
parent 8b34937b34
commit 15d86013d8
2 changed files with 12 additions and 1 deletions

View File

@@ -98,6 +98,8 @@ Detailed list of changes
- macOS: Fix --start-as=fullscreen not working when another window is already fullscreen (:iss:`7448`)
- Add option :option:`kitten @ detach-window --stay-in-tab` to keep focus in the currently active tab when moving windows (:iss:`7468`)
0.34.1 [2024-04-19]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -15,6 +15,7 @@ class DetachWindow(RemoteCommand):
match/str: Which window to detach
target_tab/str: Which tab to move the detached window to
self/bool: Boolean indicating whether to detach the window the command is run in
stay_in_tab/bool: Boolean indicating focus should remain in the active tab after windows are moved
'''
short_desc = 'Detach the specified windows and place them in a different/new tab'
@@ -31,10 +32,15 @@ class DetachWindow(RemoteCommand):
--self
type=bool-set
Detach the window this command is run in, rather than the active window.
--stay-in-tab
type=bool-set
Keep the focus on a window in the currently focused tab after moving the specified windows.
''')
def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:
return {'match': opts.match, 'target_tab': opts.target_tab, 'self': opts.self}
return {'match': opts.match, 'target_tab': opts.target_tab, 'self': opts.self, 'stay_in_tab': opts.stay_in_tab}
def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType:
windows = self.windows_for_match_payload(boss, window, payload_get)
@@ -50,9 +56,12 @@ Detach the window this command is run in, rather than the active window.
raise MatchError(match, 'tabs')
target_tab_id = tabs[0].id
kwargs = {'target_os_window_id': newval} if target_tab_id is None else {'target_tab_id': target_tab_id}
tab = boss.active_tab
for window in windows:
if window:
boss._move_window_to(window=window, **kwargs)
if payload_get('stay_in_tab') and tab is not None:
tab.make_active()
return None