fixt the Scrolling back to the bottom does not restore anchored scroll - #6683
Open
prabinKh wants to merge 1 commit into
Open
fixt the Scrolling back to the bottom does not restore anchored scroll#6683prabinKh wants to merge 1 commit into
prabinKh wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added _handle_scroll_anchor() and use it in scroll_to / _scroll_to instead of unconditionally calling release_anchor():
Release the anchor only when scrolling away from the bottom.
Re-engage the anchor when the scroll target reaches the bottom (target_y >= max_scroll_y).
2. More reliable anchor check (widget.py)
Updated _check_anchor() to use is_vertical_scroll_end instead of a raw scroll_y >= max_scroll_y comparison.
During layout, if a widget is anchored but released and scroll_y is still at the bottom edge, re-engage the anchor before applying bottom-gluing. This handles the case where content grows while the user is already at the bottom.
Test plan
Added tests/test_anchor_scroll.py with 4 tests:
Anchored widget follows new content
Scrolling up releases the anchor
Scrolling back to bottom re-engages the anchor
Anchor stays engaged while content streams after restore
Ran pytest tests/test_anchor_scroll.py -v — all 4 passed
Ran pytest tests/test_compositor.py tests/test_containers.py — no regressions
Files changed
src/textual/widget.py — anchor release/restore logic during scroll
src/textual/_compositor.py — re-check anchor during layout
tests/test_anchor_scroll.py — new test coverage