Skip to content

fix(tui): preserve viewport before message navigation - #57073

Open
HootRock wants to merge 1 commit into
anomalyco:devfrom
HootRock:preserve-message-anchor
Open

HootRock wants to merge 1 commit into
anomalyco:devfrom
HootRock:preserve-message-anchor

Conversation

@HootRock

Copy link
Copy Markdown

Issue for this PR

Closes #57059

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The first message jump after scrolling a long transcript can land near its beginning because mounting older rows changes the content above the viewport. Retain a mounted anchor's content position, compensate for that insertion, then let layout settle before choosing the next boundary. The content-coordinate delta also preserves manual scrolling that cancels a pending jump and excludes rows added below the reader.

Thanks to @xuwangaa for the report and root-cause analysis.

How did you verify your code works?

  • Real app regression fails on unchanged dev at both 44- and 100-column widths. It covers the first jump after scrolling, repeated previous/next, a first jump from the bottom, and manual cancellation during mounting.
  • Twenty repetitions pass, including another twenty with a core suite running. Independent review passed, with additional queued/first-next controls.
  • All 34 bun run check tasks pass. Windows's tracked declaration symlink placeholder was temporarily materialized from its target and restored.
  • Full Windows TUI: 1,473 passed, 12 skipped, 11 failed; unchanged source: 1,471 passed, 12 skipped, 11 failed. Nine failing cases overlap; the two head-only failures pass in an unchanged-source standalone run. These full runs are not clean. No live model calls; Linux/macOS were not run locally.

AI-assisted; reviewed and tested locally.

Screenshots / recordings

Actual 100x30 fixture frames, rendered to PNG. The same first previous-user command should reach Prompt 28:

Before: Prompt 11 After: Prompt 28
Before After

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works. I ran the #57059 reproduction (30 turns, scroll up a few wheel steps, press alt+up) on the base and with this PR. On the base, the first press lands on Prompt 11. With this PR, it lands on Prompt 28, the previous user prompt above the viewport, and the second press steps to Prompt 27. The new test passes 5 runs in a row and fails on the base. typecheck in packages/tui passes.

I checked the cancellation paths. A manual scroll during mounting keeps the same pending list, so the offset correction and the final cleanup still run. The new early return only fires after toBottom(), which resets the scroll state itself. Pinning to the bottom is turned back on by updateAwayFromBottom. Rows mounted below the view don't move the anchor, so they aren't offset.

Public API: unchanged (internal to the TUI session route).

No blocking concerns.

Before

After

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tui: first message-navigation jump can land at the top of the transcript

1 participant