Skip to content

Commit

Permalink
restoreTreeRecursive: there is no reason to continue if at least one …
Browse files Browse the repository at this point in the history
…window in the tree couldn't be restored

Related: #771

Motivation: I am not aware of any test case that would lead to problems.
The code change is purely for sanity
  • Loading branch information
nikitabobko committed Dec 5, 2024
1 parent f92dacb commit 7b88c46
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Sources/AppBundle/tree/frozen/closedWindowsCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func restoreClosedWindowsCacheIfNeeded(newlyDetectedWindow: Window) -> Bool {
return true
}

private func restoreTreeRecursive(frozenContainer: FrozenContainer, parent: NonLeafTreeNodeObject, index: Int) {
@discardableResult
private func restoreTreeRecursive(frozenContainer: FrozenContainer, parent: NonLeafTreeNodeObject, index: Int) -> Bool {
let container = TilingContainer(
parent: parent,
adaptiveWeight: frozenContainer.weight,
Expand All @@ -92,16 +93,18 @@ private func restoreTreeRecursive(frozenContainer: FrozenContainer, parent: NonL
index: index
)

loop: for (index, child) in frozenContainer.children.enumerated() {
for (index, child) in frozenContainer.children.enumerated() {
switch child {
case .window(let w):
// Stop the loop if can't find the window, because otherwise all the subsequent windows will have incorrect index
guard let window = MacWindow.get(byId: w.id) else { break loop }
guard let window = MacWindow.get(byId: w.id) else { return false }
window.bind(to: container, adaptiveWeight: w.weight, index: index)
case .container(let c):
restoreTreeRecursive(frozenContainer: c, parent: container, index: index)
// There is no reason to continue
if !restoreTreeRecursive(frozenContainer: c, parent: container, index: index) { return false }
}
}
return true
}

// Consider the following case:
Expand Down

0 comments on commit 7b88c46

Please sign in to comment.