mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
Allow specifying additional targets for detach_window
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
||||
|
||||
- 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]
|
||||
----------------------
|
||||
|
||||
@@ -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}'
|
||||
|
||||
@@ -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,)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user