mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
fix scroll to top
This commit is contained in:
@@ -320,7 +320,7 @@ class Region(NamedTuple):
|
||||
Offset: An offset required to add to region to move it inside window_region.
|
||||
"""
|
||||
|
||||
if region in window_region:
|
||||
if region in window_region and not top:
|
||||
# Region is already inside the window, so no need to move it.
|
||||
return NULL_OFFSET
|
||||
|
||||
@@ -341,19 +341,19 @@ class Region(NamedTuple):
|
||||
key=abs,
|
||||
)
|
||||
|
||||
if not (
|
||||
if top:
|
||||
delta_y = top_ - window_top
|
||||
|
||||
elif not (
|
||||
(window_bottom > top_ >= window_top)
|
||||
and (window_bottom > bottom >= window_top)
|
||||
):
|
||||
# The window needs to scroll on the Y axis to bring region in to view
|
||||
if top:
|
||||
delta_y = top_ - window_top
|
||||
else:
|
||||
delta_y = min(
|
||||
top_ - window_top,
|
||||
top_ - (window_bottom - region.height),
|
||||
key=abs,
|
||||
)
|
||||
delta_y = min(
|
||||
top_ - window_top,
|
||||
top_ - (window_bottom - region.height),
|
||||
key=abs,
|
||||
)
|
||||
return Offset(delta_x, delta_y)
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
|
||||
@@ -1805,7 +1805,7 @@ class Widget(DOMNode):
|
||||
if spacing is not None:
|
||||
window = window.shrink(spacing)
|
||||
|
||||
if window in region:
|
||||
if window in region and not top:
|
||||
return Offset()
|
||||
|
||||
delta_x, delta_y = Region.get_scroll_to_visible(window, region, top=top)
|
||||
|
||||
@@ -805,7 +805,7 @@ class Tree(Generic[TreeDataType], ScrollView, can_focus=True):
|
||||
cursor_line = meta["line"]
|
||||
if meta.get("toggle", False):
|
||||
node = self.get_node_at_line(cursor_line)
|
||||
if node is not None and self.auto_expand:
|
||||
if node is not None:
|
||||
self._toggle_node(node)
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user