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

lazy scrolling fixes #5167

Merged
merged 2 commits into from
Oct 24, 2024
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
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
Loading