Skip to content

Commit

Permalink
fix(core/tree): ensure pruning happens when applicable in merge_tabs()
Browse files Browse the repository at this point in the history
  • Loading branch information
aravinda0 committed May 2, 2024
1 parent a59a2f6 commit 5d47ca6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/qtile_bonsai/core/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,10 @@ def merge_tabs(self, src: Tab, dest: Tab, axis: AxisParam):
axis = Axis(axis)

removed_nodes = []
br_rm, _, _, _removed_nodes = self._remove(src)
br_rm, _, br_sib, _removed_nodes = self._remove(src)
removed_nodes.extend(_removed_nodes)
if br_sib is not None:
removed_nodes.extend(self._do_post_removal_pruning(br_sib))

br_rm_sc = br_rm.children[0]
dest_sc = dest.children[0]
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/core/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4021,6 +4021,32 @@ def test_merge_to_y_axis(self, tree: Tree, add_subscribers_to_tree):
assert cb_add.mock_calls == []
assert cb_remove.mock_calls == [mock.call([t1])]

def test_when_tc_is_pruned_out(self, tree: Tree):
tree.set_config("tab_bar.hide_when", "single_tab")

p1 = tree.tab()
p2 = tree.split(p1, "x")
p3 = tree.tab()
p4 = tree.split(p3, "y")

t1 = p2.get_first_ancestor(Tab)
t2 = p4.get_first_ancestor(Tab)
tree.merge_tabs(t1, t2, "x")

assert tree_matches_repr(
tree,
"""
- tc:1
- t:6
- sc.x:10
- sc.y:7
- p:8 | {x: 0, y: 0, w: 200, h: 150}
- p:9 | {x: 0, y: 150, w: 200, h: 150}
- p:4 | {x: 200, y: 0, w: 100, h: 300}
- p:5 | {x: 300, y: 0, w: 100, h: 300}
""",
)


class TestMergeToSubtab:
def test_when_src_and_dest_resolve_to_same_node_then_error_is_raised(
Expand Down

0 comments on commit 5d47ca6

Please sign in to comment.