Fix focus changing when closing non focused window before the focused one

This commit is contained in:
Kovid Goyal 2026-10-01 15:54:20 +05:30
parent cbc5382bbe
commit b4d43249b0
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 8 additions and 2 deletions

View file

@ -206,6 +206,9 @@ Detailed list of changes
status bars, file trees, etc. Create them with :code:`launch --type=window-dock`
or :code:`launch --type=tab-dock`, see :ref:`docks`
- Fix closing an unfocused window that comes before the focused window in the
layout sometimes moving focus to a different window
0.49.2 [2026-10-01]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -656,7 +656,8 @@ class WindowList:
self._active_group_idx = self._most_recent_main_group_idx()
else:
self.make_previous_group_active(notify=False)
elif self.active_group_idx >= len(self.groups):
elif self.active_group_idx > i:
# The active group shifted down by one
self._active_group_idx -= 1
if (dock := self.active_dock) is not None and (owner := self.dock_owner(dock)) is not None:
# The active normal group must remain the owner of the active dock

View file

@ -186,8 +186,10 @@ class TestLayout(BaseTest):
windows.set_active_group_idx(0)
to_remove = windows.active_window
windows.set_active_group_idx(3)
prev_window = windows.active_window
windows.remove_window(to_remove)
self.ae(windows.active_group_idx, 3)
self.ae(windows.active_group_idx, 2)
self.ae(windows.active_window, prev_window)
check_visible()
expect_ids(2, 3, 5, 6)