Skip to content

fix(nsh): scroll to the caret only once its text is laid out for the edit - #6889

Merged
M4n5ter merged 1 commit into
rust-previewfrom
fix/nsh-editor-reveal-new-line
Nov 14, 2026
Merged

M4n5ter merged 1 commit into
rust-previewfrom
fix/nsh-editor-reveal-new-line

Conversation

@UncertaintyDeterminesYou4ndMe

Copy link
Copy Markdown
Contributor

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_view in 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:

  • a paragraph just split off has no text frame yet, so its caret box is one point high at the block's corner. The view scrolled by one point and stopped (measured: the last line moved from y 60 to y 59);
  • a line that just wrapped still has the lines of before the edit, so the caret box is on the old row.

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 879 nsh-base tests pass.
  • The wrapping case is not in the headless tests, because the headless text reports one line for a wrapped paragraph. I checked it, with the other two, in a local desktop screenshot probe of the Maka composer (nine pasted lines, then Shift+Enter at the end, a break in the last line, and a long typed run): before, the caret's row was below the view in all three; after, it is in view.

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.

…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.
@M4n5ter
M4n5ter merged commit 3830579 into rust-preview Nov 14, 2026
8 of 11 checks passed
@M4n5ter
M4n5ter deleted the fix/nsh-editor-reveal-new-line branch November 14, 2026 03:16
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.

2 participants