Skip to content

Commit

Permalink
Merge pull request #5167 from Textualize/snapshit-fixes
Browse files Browse the repository at this point in the history
lazy scrolling fixes
  • Loading branch information
willmcgugan authored Oct 24, 2024
2 parents 667b3b3 + 6276d32 commit 54ba2a1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
46 changes: 33 additions & 13 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2557,7 +2557,10 @@ def _lazily_scroll_end() -> None:
level=level,
)

self.call_after_refresh(_lazily_scroll_end)
if immediate:
_lazily_scroll_end()
else:
self.call_after_refresh(_lazily_scroll_end)

def scroll_left(
self,
Expand Down Expand Up @@ -3215,18 +3218,35 @@ def scroll_visible(
"""
parent = self.parent
if isinstance(parent, Widget):
self.screen.scroll_to_widget(
self,
animate=animate,
speed=speed,
duration=duration,
top=top,
easing=easing,
force=force,
on_complete=on_complete,
level=level,
immediate=immediate,
)
if self.region:
self.screen.scroll_to_widget(
self,
animate=animate,
speed=speed,
duration=duration,
top=top,
easing=easing,
force=force,
on_complete=on_complete,
level=level,
immediate=immediate,
)
else:
# self.region is falsey which may indicate the widget hasn't been through a layout operation
# We can potentially make it do the right thing by postponing the scroll to after a refresh
self.call_after_refresh(
self.screen.scroll_to_widget,
self,
animate=animate,
speed=speed,
duration=duration,
top=top,
easing=easing,
force=force,
on_complete=on_complete,
level=level,
immediate=immediate,
)

def scroll_to_center(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/textual/widgets/_collapsible.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _watch_collapsed(self, collapsed: bool) -> None:
self.post_message(self.Collapsed(self))
else:
self.post_message(self.Expanded(self))
self.call_later(self.scroll_visible)
self.call_after_refresh(self.scroll_visible)

def _update_collapsed(self, collapsed: bool) -> None:
"""Update children to match collapsed state."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


class ScrollOffByOne(App):
AUTO_FOCUS = None
HOVER_EFFECTS_SCROLL_PAUSE = 0.0

def compose(self) -> ComposeResult:
Expand Down
1 change: 1 addition & 0 deletions tests/snapshot_tests/snapshot_apps/scroll_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class ScrollOffByOne(App):
"""Scroll to item 50."""

AUTO_FOCUS = None
HOVER_EFFECTS_SCROLL_PAUSE = 0

def compose(self) -> ComposeResult:
Expand Down
5 changes: 1 addition & 4 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,6 @@ def test_dock_scroll_off_by_one(snap_compare):
assert snap_compare(
SNAPSHOT_APPS_DIR / "dock_scroll_off_by_one.py",
terminal_size=(80, 25),
press=["_"],
)


Expand All @@ -962,9 +961,7 @@ def compose(self) -> ComposeResult:

def test_scroll_to(snap_compare):
# https://github.com/Textualize/textual/issues/2525
assert snap_compare(
SNAPSHOT_APPS_DIR / "scroll_to.py", terminal_size=(80, 25), press=["_"]
)
assert snap_compare(SNAPSHOT_APPS_DIR / "scroll_to.py", terminal_size=(80, 25))


def test_auto_fr(snap_compare):
Expand Down

0 comments on commit 54ba2a1

Please sign in to comment.