Repository navigation
fix(tui): keep the view in place when an older page is measured late #273
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
Changes from all commits
6958818
fc42c78
4d83377
9b8d772
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ | |
| from textual.app import ComposeResult | ||
| from textual.widget import Widget | ||
|
|
||
| #: Refreshes an older page's scroll-past waits through for the new rows to be measured. | ||
| _KEEP_PLACE_TRIES = 5 | ||
|
|
||
|
|
||
| class ThreadScroll(VerticalScroll): | ||
| """The scrolling body. ↑/↓ select a message (for ``r``) instead of scrolling a line; | ||
|
|
@@ -102,6 +105,10 @@ def __init__(self) -> None: | |
| super().__init__(id="thread") | ||
| self._unseen = 0 | ||
| self._was_pinned = True | ||
| #: Bumped when a different conversation is shown, so a keep-place retry left over | ||
| #: from the previous one stands down. Not by every ``show``: a live refresh of the same | ||
| #: conversation must not cancel the scroll past an older page it has not reached yet. | ||
| self._conversation = 0 | ||
|
|
||
| def compose(self) -> ComposeResult: | ||
| with ThreadScroll(id="thread-scroll"): | ||
|
|
@@ -139,11 +146,24 @@ def show( | |
| stick = reset or (self.pinned and not prepended) | ||
| scroller = self.scroller | ||
| old_height, old_y = scroller.virtual_size.height, scroller.scroll_y | ||
| if reset: | ||
| self._conversation += 1 | ||
| conversation = self._conversation | ||
| self.query_one("#thread-body", Static).update(body) | ||
| if prepended and not reset: | ||
|
|
||
| def keep_place() -> None: | ||
| def keep_place(tries: int = _KEEP_PLACE_TRIES) -> None: | ||
| if self._conversation != conversation or scroller.scroll_y != old_y: | ||
| # Another conversation was opened, or the reader scrolled, while this | ||
| # waited: either one owns the position now. | ||
| return | ||
| grown = scroller.virtual_size.height - old_height | ||
| if grown <= 0 and tries > 1: | ||
| # The refresh this waited for can land before the layout that measures | ||
| # the new rows (a loaded loop); scrolling by 0 would leave the reader at | ||
| # the top of the longer thread. Wait for the next one. | ||
| scroller.call_after_refresh(keep_place, tries - 1) | ||
| return | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| scroller.scroll_to(y=old_y + max(grown, 0), animate=False) | ||
|
|
||
| scroller.call_after_refresh(keep_place) | ||
|
Comment on lines
+155
to
169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 · On a very slow machine, if the older page still isn't laid out after five screen refreshes, the view still jumps to the top of the thread. The fix waits for a set number of refreshes rather than for the new rows' height. Reply Details for agents: evidence, failure scenario, verification, proving testkeep_place waits a fixed count of call_after_refresh callbacks (_KEEP_PLACE_TRIES = 5) for virtual_size.height to grow, then scrolls by max(grown, 0). The wait is counted in refresh callbacks, not in measured layout. If the new rows are still unmeasured after the 5th callback, grown is 0 and the scroll is to old_y, i.e. the top of the longer thread, which is the exact bug this PR claims to fix. The patch narrows the window; it does not make the scroll depend on the measurement. Evidence: Read thread.py:142-161. Retry is bounded by tries > 1 (line 150) and the fallback is scroll_to(old_y + max(grown, 0)) (line 156). Callers: app.py:936-942 and app.py:1829 (prepended=bool(added)). No wall-clock or layout-based wait exists. Textual sources are not in the checkout, so I could not confirm how many layout passes a call_after_refresh cycle actually spans; the claim rests only on the bounded count in this file. Failure scenario User is at the top of a thread and scrolls up, triggering an older page (app.py:1829 passes prepended=True). On a heavily loaded machine the Static body's new height is not laid out within the 5 scheduled refreshes. keep_place runs on the 5th callback with grown == 0, scrolls to old_y, and the reader is left at the top of the longer thread with the same lines no longer in view. How this was verified (read-only-reasoning) I read thread.py:142-161. The retry is bounded at 5 and the fallback is scroll_to(old_y + max(grown, 0)). I did not open the app.py callers; I took them from the candidate's evidence. Textual's layout timing is not in the checkout, so I could not check how many layouts a refresh spans. Reachable from: ThreadView.show(prepended=True), called from the app older-page load path. Proving test lens concurrency-time · symbol ThreadView.show
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declined: an unbounded wait has no end in the case where the prepended rows really add no height, and a time-based wait would read the wall clock in a path the tests drive by refresh. Five refreshes is several times what the merge-queue repro needed (it failed with zero retries and passed with one). If a reader still lands at the top, the view is no worse than before this PR, and the new scroll-guard means a reader who moves isn't overridden. Generated by Claude Code
vycari-review[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.