From 32790de26a958e104d94f39fc12c146ad0bc0f0f Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 25 May 2023 20:49:50 +0100 Subject: [PATCH] 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. --- src/textual/widgets/_directory_tree.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/textual/widgets/_directory_tree.py b/src/textual/widgets/_directory_tree.py index e6b81abee..c0bb2c505 100644 --- a/src/textual/widgets/_directory_tree.py +++ b/src/textual/widgets/_directory_tree.py @@ -271,6 +271,7 @@ class DirectoryTree(Tree[DirEntry]): node: The Tree node to populate. content: The collection of `Path` objects to populate the node with. """ + node.remove_children() for path in content: node.add( path.name,