Skip to content

Commit

Permalink
normalizeContainersRecursive fix bug: flatten leaf windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Oct 15, 2023
1 parent acc507e commit 81d5069
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/tree/TilingContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class TilingContainer: TreeNode, NonLeafTreeNode {

extension TilingContainer {
func normalizeContainersRecursive() {
if let child = children.singleOrNil() as? TilingContainer, config.autoFlattenContainers {
if let child = children.singleOrNil(), !isRootContainer, config.autoFlattenContainers {
child.unbindFromParent()
let parent = parent
let previousBinding = unbindFromParent()
child.bindTo(parent: parent, adaptiveWeight: previousBinding.adaptiveWeight, index: previousBinding.index)
child.normalizeContainersRecursive()
(child as? TilingContainer)?.normalizeContainersRecursive()
} else {
for child in children {
(child as? TilingContainer)?.normalizeContainersRecursive()
Expand Down
20 changes: 20 additions & 0 deletions test/tree/TreeNodeTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ final class TreeNodeTest: XCTestCase {
XCTAssertNotEqual(root, nil)
}

func testNormalizeContainers_dontRemoveRoot_autoFlattenContainers() {
config.autoFlattenContainers = true
weak var root = Workspace.get(byName: name).rootTilingContainer
XCTAssertNotEqual(root, nil)
XCTAssertTrue(root!.isEffectivelyEmpty)
root?.normalizeContainersRecursive()
XCTAssertNotEqual(root, nil)
}

func testNormalizeContainers_singleWindowChild() {
config.autoFlattenContainers = true
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TilingContainer.newHList(parent: $0, adaptiveWeight: 1).apply {
TestWindow(id: 1, parent: $0)
}
}
root.normalizeContainersRecursive()
XCTAssertTrue((root.children.singleOrNil() as? Window)?.windowId == 1)
}

func testNormalizeContainers_removeEffectivelyEmpty() {
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TilingContainer.newVList(parent: $0, adaptiveWeight: 1).apply {
Expand Down

0 comments on commit 81d5069

Please sign in to comment.