macOS: fix toggle_visibility behaviour with tabbed windows

This fixes regression of #5690, which kind of comes from #9576. 05b42919d5 (before #9576) has weird behaviours too, restored windows are not properly focused. With this pr, we only order `selectedWindow` front so we won't mess up with its selection state and the order of the tab group.
pull/9742/head
Lukas 2025-11-28 10:14:07 +01:00
parent 199119967b
commit 94f88c8b54
No known key found for this signature in database
GPG Key ID: 845CB61BD38F4E49
1 changed files with 11 additions and 2 deletions

View File

@ -1184,10 +1184,19 @@ class AppDelegate: NSObject,
// want to bring back these windows if we remove the toggle.
//
// We also ignore fullscreen windows because they don't hide anyways.
self.hiddenWindows = NSApp.windows.filter {
var visibleWindows = [Weak<NSWindow>]()
NSApp.windows.filter {
$0.isVisible &&
!$0.styleMask.contains(.fullScreen)
}.map { Weak($0) }
}.forEach { window in
// We only keep track of selectedWindow if it's in a tabGroup,
// so we can keep its selection state when restoring
let windowToHide = window.tabGroup?.selectedWindow ?? window
if !visibleWindows.contains(where: { $0.value === windowToHide }) {
visibleWindows.append(Weak(windowToHide))
}
}
self.hiddenWindows = visibleWindows
}
func restore() {