From 17ba51697dd277a177cfc49e8108b6591d88d699 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 26 Feb 2024 09:31:30 +0000 Subject: [PATCH 1/2] Fix DirectoryTree.path no longer reacting to new values Fixes #4208 --- CHANGELOG.md | 1 + src/textual/widgets/_directory_tree.py | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3534132aa..2df2b1993d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed `Sparkline` not working with data in a `deque` https://github.com/Textualize/textual/issues/3899 - Tooltips are now cleared when the related widget is no longer under them https://github.com/Textualize/textual/issues/3045 - Simplified tree-sitter highlight queries for HTML, which also seems to fix segfault issue https://github.com/Textualize/textual/pull/4195 +- Fixed `DirectoryTree.path` no longer reacting to new values https://github.com/Textualize/textual/issues/4208 ## [0.52.1] - 2024-02-20 diff --git a/src/textual/widgets/_directory_tree.py b/src/textual/widgets/_directory_tree.py index fbddcb75d9..16f9d0a100 100644 --- a/src/textual/widgets/_directory_tree.py +++ b/src/textual/widgets/_directory_tree.py @@ -332,6 +332,7 @@ async def watch_path(self) -> None: If the path is changed the directory tree will be repopulated using the new value as the root. """ + self.reset_node(self.root, str(self.path), DirEntry(self.PATH(self.path))) await self.reload() def process_label(self, label: TextType) -> Text: From a9c51612e713e540325f7c129438d10edc3b24e4 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 26 Feb 2024 10:01:41 +0000 Subject: [PATCH 2/2] Add a unit test for changing DirecotryTree.path --- tests/directory_tree/test_change_path.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/directory_tree/test_change_path.py diff --git a/tests/directory_tree/test_change_path.py b/tests/directory_tree/test_change_path.py new file mode 100644 index 0000000000..1b73f3c09d --- /dev/null +++ b/tests/directory_tree/test_change_path.py @@ -0,0 +1,20 @@ +from pathlib import Path + +from textual.app import App, ComposeResult +from textual.widgets import DirectoryTree + + +class DirectoryTreeApp(App[None]): + + def compose(self) -> ComposeResult: + yield DirectoryTree(".") + + +async def test_change_directory_tree_path(tmpdir: Path) -> None: + """The DirectoryTree should react to the path changing.""" + + async with DirectoryTreeApp().run_test() as pilot: + assert pilot.app.query_one(DirectoryTree).root.data.path == Path(".") + pilot.app.query_one(DirectoryTree).path = tmpdir + await pilot.pause() + assert pilot.app.query_one(DirectoryTree).root.data.path == tmpdir