Skip to content

Commit 62fbda8

Browse files
committed
When re-attaching a detached tab preserve internal layout state such as biases and orientations
Fixes kovidgoyal#8106
1 parent 33207a5 commit 62fbda8

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ Detailed list of changes
109109

110110
- Fix enlarging window when a long line is wrapped between the first line of the scrollback buffer and the screen inserting a spurious newline (:iss:`7033`)
111111

112+
- When re-attaching a detached tab preserve internal layout state such as biases and orientations (:iss:`8106`)
113+
112114
0.37.0 [2024-10-30]
113115
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114116

kitty/layout/base.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,7 @@ class Layout:
223223
only_active_window_visible = False
224224

225225
def __init__(self, os_window_id: int, tab_id: int, layout_opts: str = '') -> None:
226-
self.os_window_id = os_window_id
227-
self.tab_id = tab_id
228-
self.set_active_window_in_os_window = partial(set_active_window, os_window_id, tab_id)
226+
self.set_owner(os_window_id, tab_id)
229227
# A set of rectangles corresponding to the blank spaces at the edges of
230228
# this layout, i.e. spaces that are not covered by any window
231229
self.blank_rects: List[Rect] = []
@@ -234,6 +232,12 @@ def __init__(self, os_window_id: int, tab_id: int, layout_opts: str = '') -> Non
234232
self.full_name = f'{self.name}:{layout_opts}' if layout_opts else self.name
235233
self.remove_all_biases()
236234

235+
def set_owner(self, os_window_id: int, tab_id: int) -> None:
236+
# Useful when moving a layout from one tab to another typically a detached tab being re-attached
237+
self.os_window_id = os_window_id
238+
self.tab_id = tab_id
239+
self.set_active_window_in_os_window = partial(set_active_window, os_window_id, tab_id)
240+
237241
def bias_increment_for_cell(self, all_windows: WindowList, is_horizontal: bool) -> float:
238242
self._set_dimensions()
239243
return self.calculate_bias_increment_for_a_single_cell(all_windows, is_horizontal)

kitty/tabs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,14 @@ def apply_options(self, is_active: bool) -> None:
184184
def take_over_from(self, other_tab: 'Tab') -> None:
185185
self.name, self.cwd = other_tab.name, other_tab.cwd
186186
self.enabled_layouts = list(other_tab.enabled_layouts)
187-
if other_tab._current_layout_name:
188-
self._set_current_layout(other_tab._current_layout_name)
189187
self._last_used_layout = other_tab._last_used_layout
188+
if clname := other_tab._current_layout_name:
189+
cl = other_tab.current_layout
190+
other_tab._set_current_layout(clname)
191+
cl.set_owner(self.os_window_id, self.id)
192+
self.current_layout: Layout = cl
193+
self._current_layout_name = clname
194+
self.mark_tab_bar_dirty()
190195
for window in other_tab.windows:
191196
detach_window(other_tab.os_window_id, other_tab.id, window.id)
192197
self.windows = other_tab.windows

0 commit comments

Comments
 (0)