Repository navigation
fix(nsh): scroll to the caret only once its text is laid out for the edit - #6889
Merged
Merged
Conversation
…edit A scroll request was carried out with the first layout report after the edit. A block reports its frame, its text's frame and its lines one after another, so at that point the head's box was one point high at the corner of a new block, or still on the row it had before a line wrapped. In an editor at its height limit the view moved by a point, or to the wrong row, and the caret stayed below it until the next keystroke: Shift+Enter at the end of a full composer, a break in its last line, a line wrapping there. The request now waits until the head's text has the frame and the lines of its present content.
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.
Problem
In a composer that has reached its height limit, Shift+Enter at the end of the draft adds the line, but the view does not follow: the new line and the caret stay below the view until the next keystroke. The same happens when a break splits the last line, and when a line typed at the bottom wraps onto another row. This is the rust-preview form of #5811 (the TypeScript desktop had it in #5812).
Cause
scroll_into_viewin the rich editor runs when the selection or the layout changes, and clears the request the first time the head has a box. After an edit, a block reports its frame, its text's frame and its lines one after another. At the first report:The next keystroke goes into a block that is already laid out, which is why it looked as if one more key fixed it.
Fix
The scroll request waits until the head's text is laid out as it is now: its render has the present content (
map.size), its text has its frame, and its lines are those of that render (laid_len, set when the lines are reported). Nothing else changes: the request is still carried out once, and a head outside a textblock is handled as before.Tests
rich_editor::sizing: two new headless tests on a full editor, a line broken off at the end and a line broken in two. Both fail without the fix. All 879nsh-basetests pass.AI use
Diagnosed and written with Claude Code (Claude Fable 5.2): it reproduced the report in a desktop probe, traced the layout reports to find the one-point scroll, and wrote the fix and tests. I reported the symptom from daily use.