mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Ensure a node has no children before populating it
I'm struggling to recreate https://github.com/Textualize/frogmouth/issues/50 in a controlled way, but reviewing the code here makes me think that this is a good idea anyway. While DirectoryTree should not end up in _populate_node if a node has already been populated, it's also the case that it's an all-or-nothing thing; it makes sense to clear out the children of the node before populating it; at least in a belt-and-braces way.
This commit is contained in:
@@ -271,6 +271,7 @@ class DirectoryTree(Tree[DirEntry]):
|
|||||||
node: The Tree node to populate.
|
node: The Tree node to populate.
|
||||||
content: The collection of `Path` objects to populate the node with.
|
content: The collection of `Path` objects to populate the node with.
|
||||||
"""
|
"""
|
||||||
|
node.remove_children()
|
||||||
for path in content:
|
for path in content:
|
||||||
node.add(
|
node.add(
|
||||||
path.name,
|
path.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user