diff --git a/CHANGELOG.md b/CHANGELOG.md
index c01e58d02..2abe8f5d7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- Breaking change: `TreeNode` can no longer be imported from `textual.widgets`; it is now available via `from textual.widgets.tree import TreeNode`. https://github.com/Textualize/textual/pull/1637
+- `Tree` now shows a (subdued) cursor for a highlighted node when focus has moved elsewhere https://github.com/Textualize/textual/issues/1471
### Fixed
diff --git a/src/textual/widgets/_tree.py b/src/textual/widgets/_tree.py
index 415cb9e4e..2f3d073cf 100644
--- a/src/textual/widgets/_tree.py
+++ b/src/textual/widgets/_tree.py
@@ -341,11 +341,15 @@ class Tree(Generic[TreeDataType], ScrollView, can_focus=True):
}
Tree > .tree--cursor {
- background: $secondary;
+ background: $secondary-darken-2;
color: $text;
text-style: bold;
}
+ Tree:focus > .tree--cursor {
+ background: $secondary;
+ }
+
Tree > .tree--highlight {
text-style: underline;
}
@@ -925,7 +929,7 @@ class Tree(Generic[TreeDataType], ScrollView, can_focus=True):
label_style += self.get_component_rich_style(
"tree--highlight", partial=True
)
- if self.cursor_line == y and self.has_focus:
+ if self.cursor_line == y:
label_style += self.get_component_rich_style(
"tree--cursor", partial=False
)
diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr
index 99f87096c..5a8c647bf 100644
--- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr
+++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr
@@ -14302,132 +14302,133 @@
font-weight: 700;
}
- .terminal-2744759648-matrix {
+ .terminal-1336653930-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}
- .terminal-2744759648-title {
+ .terminal-1336653930-title {
font-size: 18px;
font-weight: bold;
font-family: arial;
}
- .terminal-2744759648-r1 { fill: #e2e3e3 }
- .terminal-2744759648-r2 { fill: #c5c8c6 }
- .terminal-2744759648-r3 { fill: #008139 }
+ .terminal-1336653930-r1 { fill: #e2e3e3 }
+ .terminal-1336653930-r2 { fill: #1a1000;font-weight: bold }
+ .terminal-1336653930-r3 { fill: #c5c8c6 }
+ .terminal-1336653930-r4 { fill: #008139 }
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
- TreeApp
+ TreeApp
-
-
-
- ▼ Dune
- └── ▼ Characters
- ├── Paul
- ├── Jessica
- └── Chani
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ ▼ Dune
+ └── ▼ Characters
+ ├── Paul
+ ├── Jessica
+ └── Chani
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+