fix scroll to top

This commit is contained in:
Will McGugan
2022-12-16 09:09:29 +00:00
parent 4512d33c90
commit 6bc7e98889
3 changed files with 12 additions and 12 deletions

View File

@@ -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:

View File

@@ -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)

View File

@@ -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: