From 6e1f18910a249b51540bae115fbcd19cd7e749ea Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 31 Jan 2023 15:51:31 +0000 Subject: [PATCH 1/3] Keep a visible, but darker, cursor in Tree when it doesn't have focus See #1471. It seems useful and important for a Tree to still have a cursor visible even when it doesn't have focus -- that ways someone can build a UI where the user can tab away from the tree to something that relates to the node, and still see which node is in play. --- src/textual/widgets/_tree.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 ) From f2e756b69539857d6fc731d9f64e193343281b0a Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 31 Jan 2023 15:54:27 +0000 Subject: [PATCH 2/3] Update the CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5168a2032..66033a6e3 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 From b0a29050cf5498a15525f1c2c9e1ad8e6738cb3c Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 31 Jan 2023 16:20:41 +0000 Subject: [PATCH 3/3] Update snapshots after change of unfocused tree cursor handling --- .../__snapshots__/test_snapshots.ambr | 113 +++++++++--------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index d347bcc03..7b569f3fe 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -14147,132 +14147,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 + + + + + + + + + + + + + + + + + +