Merge pull request #2482 from davep/tree-lines-fix

This commit is contained in:
Dave Pearson
2023-05-04 18:30:28 +01:00
committed by GitHub
3 changed files with 11 additions and 3 deletions

View File

@@ -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`
## [0.23.0] - 2023-05-03

View File

@@ -76,11 +76,13 @@ class Reactive(Generic[ReactiveType]):
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.
@@ -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,
)

View File

@@ -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."""
@@ -976,8 +976,8 @@ class Tree(Generic[TreeDataType], ScrollView, can_focus=True):
"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.