Skip to content

rich_editor: Keep a touch selection's knobs whole on the first and last lines - #4258

Open
huacnlee wants to merge 2 commits into
mainfrom
agent/T-13014-richeditor-knob-clip
Open

huacnlee wants to merge 2 commits into
mainfrom
agent/T-13014-richeditor-knob-clip

Conversation

@huacnlee

@huacnlee huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member

Fixes #4251.

On iOS and Android, the touch selection's handles were children of the content box, inside the scroll view, the unpadded box around it and the editor's root. All three clip, so the start's knob above the first line and the end's knob below the last line were cut off, whatever the root's padding.

What changed

  • On touch screens the handles (and Android's insertion handle) are now in a layer over the viewport. The layer sits beside the scroll view, inside a box that does not clip, and the root no longer clips on touch screens. The viewport box inside it still clips the text, so the knobs can hang into the root's padding and past the editor, as UIKit's and Android's own handles do.
  • The handles follow the scroll offset themselves (content box → viewport coordinates). A handle hides once the middle of its line leaves the viewport, so it is never drawn over the UI around the editor. A hidden handle takes no touches.
  • Desktops are unchanged: the root still clips and there is no handle layer.
  • No public API changes.

Testing

  • New headless tests in crates/nsh-base/tests/base/rich_editor/touch.rs, using the issue's styles (root minHeight 96, padding 12/8, plus a 2pt border, inside a view with 16pt padding):
    • the_knobs_of_a_selection_on_the_first_and_last_lines_show_whole: each knob's box, cut by every clipping ancestor and scroll view, equals its full box. Also checks that the stems line up with the line, past the border and padding.
    • the_knobs_of_a_selection_across_lines_show_whole: the same for a multi-line selection.
    • the_start_s_knob_above_the_first_line_drags_its_end: a finger on the start knob (outside the content box) drags the selection to the start of the text.
    • a_handle_goes_when_its_line_scrolls_out_of_view: after scrolling the selected line out of view, both handles hide.
  • On main the three visibility and scroll tests fail and the drag test passes. The headless engine does not model native hit-testing against clipped bounds, so the drag test guards against regressions; it does not reproduce the bug.
  • cargo test -p nsh-base --test base rich_editor:: passes: 311 passed, plus one Linux desktop timing test that failed under parallel load and passes 3/3 on its own. cargo clippy -p nsh-base --tests is clean.
  • Not yet verified on a simulator or device: the iOS simulator on the test host is unavailable. Before and after screenshots and a drag check on the iOS simulator will follow in a comment.

Risk

  • On touch screens, a root with rounded corners and little or no padding no longer clips content to those corners. Only the rectangular viewport box clips now, so a code block background or an image at the very edge can paint past the curve. Desktop is unaffected.
  • The handles now follow scroll_y from on_scroll rather than scrolling natively with the content, so they may trail the text by a frame during momentum scrolling. This needs a check on a device.
  • While a line is partly visible, its handle's stem and knob can paint over the root's padding or just outside the editor. This is intended, as native handles do it too.

How to revert

Revert this PR. No data, API or migration involved.

🤖 Generated with Claude Code

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

…st lines

On touch screens the selection handles (and Android's insertion handle)
were children of the content box, inside the scroll view, the unpadded
box around it and the root, all of which clip: the start's knob above the
first line and the end's below the last were cut off (#4251).

The handles now live in a layer over the viewport, beside the scroll
view in a box that does not clip, and the root no longer clips on touch
screens (the viewport inside it still clips the text). They follow the
scroll offset themselves and go, taking no touches, once the middle of
their line leaves the viewport. Desktops are unchanged.

Fixes #4251

Agent: rust-maintainer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@huacnlee

huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

iOS simulator check: before / after

Head f50df97 vs. its merge base on main (5c542c8), iPhone 17 simulator (iOS 26.5), debug host built from a checkout with only crates/nsh-base/src/rich_editor and editor/touch.rs swapped between the two. Editor styles as in #4251 (root minHeight 96, padding 12/8, outer view padding 16). The selection is made with a long press (the test driver has no double tap and lands at the middle of a text node, so the first line is "The quick brown fox effortlessly jumps." and the long press selects "effortlessly"; same line, same position as the issue's "quick").

app.layout() on the two handle views reports clipped: true on main in every scenario below and clipped: false on this branch.

1. Selection on the first (only) line. Before: the start knob is gone, cut at the content box's top. After: both knobs whole; the start knob hangs into the root's top padding.

first line

2. Selection from the first line across lines (end handle dragged down to line 3). Both builds extend the selection the same way; before, the start knob is missing.

multi-line

3. Dragging the start knob. Dragged 60 pt left from "unquestionably" to "b|rown": the selection grows on both builds (the hit area still takes the drag on main, as the PR says), but only this branch shows the knob being dragged.

drag start

4. Editor with maxHeight: 200, scrolling.

  • Selection made at the top, then scrolled 20 pt and 220 pt: on this branch the start handle hides once its line's middle leaves the viewport (layout returns no handle), and the end handle stays on its line and moves with it. On main the start handle is still there, just clipped out of view.
  • Scrolled back: both handles are back on their lines on both builds.

scroll 20
scroll 220

Note: the first 20 pt swipe (the driver's scroll, starting at the editor's middle) also moved the selection's end down to line 4. main does exactly the same, so it is not from this PR.

Not verified: lag of the handles behind the text during momentum scrolling. The driver's steps wait for the gesture to settle before the screenshot, so every frame I could capture shows the handle on its line; this still needs a look on a device or a screen recording.

5. Root with borderRadius: 24, a 1 pt border and no padding (paragraphs given a background so the edge is visible). This is the trade-off listed under Risk, and it does show: on main the paragraph backgrounds are cut to the rounded corners; on this branch they paint square past the corners and over the border.

rounded root

Every handle check above (1-4) passes. Item 5 is a visible regression for an editor with a rounded root and no padding: a card-style composer with a background on its first or last block would show it. One way to keep the fix and the corners: on touch screens, give the clipping viewport box the root's corner radius (minus the border) when the root has no padding, or clip the root but leave the handle layer outside it.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

On a touch screen the root no longer clips, so the selection handles'
knobs can hang past the first and last lines. Without padding, a rounded
root then let the text and its backgrounds draw square past its corners
and over its border.

The clipping viewport now takes the root's corners inside its border and
padding through an internal core flag (`parent_corners`): a view with it
is mounted with its parent's inner radii, passed on through a parent that
has it too, and is restyled when the parent is. No public API changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent: rust-maintainer
@huacnlee

huacnlee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Follow-up to the regression found in the iOS check (item 5 of #4258 (comment)): with a rounded root, a border and no padding, the text's backgrounds drew square past the corners and over the border on touch screens.

Fixed in 29c6236. On touch screens the clipping viewport now takes the root's corners, inset by the root's border and padding. The knobs still hang outside the root.

  • How it works: an internal core flag, parent_corners (Prop::ParentCorners, #[doc(hidden)], not exposed to JS). A view with the flag is mounted with its parent's inner radii, which CSS calls the content edge. A flagged parent passes the radii on, and the view is restyled whenever its parent is restyled or it moves to another parent. The radii follow whatever sets them: a class, the inline style, or per-corner values. RichEditor sets the flag on its touch-only wrapper and on its viewport. There is no public API change.
  • Testing:
    • New headless test a_rounded_root_clips_the_text_to_its_corners (radius 24, 1pt border, no padding). The viewport clips at 23pt and both knobs still show whole. It fails without the change.
    • The 4 existing knob tests pass. nsh-base rich_editor: 313 passed. nsh-core lib: 2164 passed, including the new parent_corners_follow_the_parent_inside_its_border_and_padding, which covers class, padding and inline radii and the restyle of nested flagged views.
    • Clippy is clean.
  • Performance: when a view is restyled, the core now also checks a small set of flagged views and returns at once when the set is empty. In a release build, restyling 3,000 sibling views by class over 40 commits took 1.93 ms per commit before and 1.99 ms after, inside run-to-run noise. Each RichEditor adds two entries to the set, and they are removed when the view is.
  • Not verified: the iOS simulator before/after screenshots have not been retaken yet. Percentage radii are not covered because ViewStyle keeps radii in points.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

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.

RichEditor (iOS): a touch selection's knobs are clipped on the first and last lines

1 participant