Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the drawing of Tree lines in respect to things being selected #2482

Merged
merged 6 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Fixed crash when creating a `DirectoryTree` starting anywhere other than `.`
- Fixed line drawing in `Tree` when `Tree.show_root` is `True` https://github.com/Textualize/textual/issues/2397
- Fixed line drawing in `Tree` not marking branches as selected when first getting focus https://github.com/Textualize/textual/issues/2397

### Changed

- The DataTable cursor is now scrolled into view when the cursor coordinate is changed programmatically https://github.com/Textualize/textual/issues/2459
- run_worker exclusive parameter is now `False` by default https://github.com/Textualize/textual/pull/2470
- Added `always_update` as an optional argument for `reactive.var`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 isn't an "Added" line a feature that was added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally yes but really this just changes the behaviour of var rather than adds something new. Felt a bit grand to have it in the added section.


## [0.23.0] - 2023-05-03

Expand Down
5 changes: 5 additions & 0 deletions src/textual/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ def __rich_repr__(self) -> rich.repr.Result:
def var(
cls,
default: ReactiveType | Callable[[], ReactiveType],
always_update: bool = False,
) -> Reactive:
"""A reactive variable that doesn't update or layout.

Args:
default: A default value or callable that returns a default.
always_update: Call watchers even when the new value equals the old value.

Returns:
A Reactive descriptor.
Expand Down Expand Up @@ -326,18 +328,21 @@ class var(Reactive[ReactiveType]):
Args:
default: A default value or callable that returns a default.
init: Call watchers on initialize (post mount).
always_update: Call watchers even when the new value equals the old value.
"""

def __init__(
self,
default: ReactiveType | Callable[[], ReactiveType],
init: bool = True,
always_update: bool = False,
) -> None:
super().__init__(
default,
layout=False,
repaint=False,
init=init,
always_update=always_update,
)


Expand Down
6 changes: 3 additions & 3 deletions src/textual/widgets/_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ class Tree(Generic[TreeDataType], ScrollView, can_focus=True):
"""Show the root of the tree."""
hover_line = var(-1)
"""The line number under the mouse pointer, or -1 if not under the mouse pointer."""
cursor_line = var(-1)
cursor_line = var(-1, always_update=True)
"""The line with the cursor, or -1 if no cursor."""
show_guides = reactive(True)
"""Enable display of tree guide lines."""
Expand Down Expand Up @@ -976,8 +976,8 @@ def _render_line(self, y: int, x1: int, x2: int, base_style: Style) -> Strip:
"tree--guides-selected", partial=True
)

hover = self.root._hover
selected = self.root._selected and self.has_focus
hover = line.path[0]._hover
selected = line.path[0]._selected and self.has_focus

def get_guides(style: Style) -> tuple[str, str, str, str]:
"""Get the guide strings for a given style.
Expand Down