When re-attaching a detached tab preserve internal layout state such as biases and orientations

Fixes #8106
This commit is contained in:
Kovid Goyal
2024-12-06 19:54:10 +05:30
parent 33207a57ba
commit 62fbda8c9b
3 changed files with 16 additions and 5 deletions

View File

@@ -109,6 +109,8 @@ Detailed list of changes
- 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`)
- When re-attaching a detached tab preserve internal layout state such as biases and orientations (:iss:`8106`)
0.37.0 [2024-10-30]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -223,9 +223,7 @@ class Layout:
only_active_window_visible = False
def __init__(self, os_window_id: int, tab_id: int, layout_opts: str = '') -> None:
self.os_window_id = os_window_id
self.tab_id = tab_id
self.set_active_window_in_os_window = partial(set_active_window, os_window_id, tab_id)
self.set_owner(os_window_id, tab_id)
# A set of rectangles corresponding to the blank spaces at the edges of
# this layout, i.e. spaces that are not covered by any window
self.blank_rects: List[Rect] = []
@@ -234,6 +232,12 @@ class Layout:
self.full_name = f'{self.name}:{layout_opts}' if layout_opts else self.name
self.remove_all_biases()
def set_owner(self, os_window_id: int, tab_id: int) -> None:
# Useful when moving a layout from one tab to another typically a detached tab being re-attached
self.os_window_id = os_window_id
self.tab_id = tab_id
self.set_active_window_in_os_window = partial(set_active_window, os_window_id, tab_id)
def bias_increment_for_cell(self, all_windows: WindowList, is_horizontal: bool) -> float:
self._set_dimensions()
return self.calculate_bias_increment_for_a_single_cell(all_windows, is_horizontal)

View File

@@ -184,9 +184,14 @@ class Tab: # {{{
def take_over_from(self, other_tab: 'Tab') -> None:
self.name, self.cwd = other_tab.name, other_tab.cwd
self.enabled_layouts = list(other_tab.enabled_layouts)
if other_tab._current_layout_name:
self._set_current_layout(other_tab._current_layout_name)
self._last_used_layout = other_tab._last_used_layout
if clname := other_tab._current_layout_name:
cl = other_tab.current_layout
other_tab._set_current_layout(clname)
cl.set_owner(self.os_window_id, self.id)
self.current_layout: Layout = cl
self._current_layout_name = clname
self.mark_tab_bar_dirty()
for window in other_tab.windows:
detach_window(other_tab.os_window_id, other_tab.id, window.id)
self.windows = other_tab.windows