Repository navigation
fix: Cull text grippers instead of locking scroll (backport #24132) - #24250
Merged
kazo0 merged 7 commits intoAug 28, 2026
Merged
Conversation
A live touch caret in a TextBox pinned its enclosing ScrollViewer: the offset was rewritten back onto the TextBox after every scroll and touch inertia was discarded outright, leaving forms the user could not scroll away from. Remove that clamp and fix the defect it was working around - selection grippers live in a popup no ScrollViewer clips, so they kept painting at their old screen position once the TextBox scrolled out of view - by culling them against the host's ancestor-clipped bounds instead. Culling tests the point the thumb hangs from rather than the caret line as a whole (as native Android does), so a line straddling the viewport edge no longer paints a whole thumb past it. This supersedes the scroll-lock workaround; the test that asserted the TextBox stayed pinned now asserts the user's scroll sticks, and gripper culling is covered directly. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit b5ef5ae)
Cull() collapses the gripper, and collapsing an element releases its pointer captures (UIElement.Pointers.ClearPointersStateIfNeeded). So culling the gripper the finger is holding aborted the drag mid-gesture: the remaining moves were dropped and the release never reached the gripper, leaving the selection toolbar closed too. Reachable since the grippers started culling against the ancestor-clipped bounds rather than the raw ones - a partially-scrolled-out control never culled before, so a drag inside one could not cross the clip edge. The trade is that a dragged gripper may paint outside the clip for the duration of the gesture: transient, and under the finger. Native avoids even that by auto-scrolling the container at the edge, which we don't do. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 2543434)
Both grippers subscribed to CompositionTarget.FrameRendered individually and invoked the same TextSelectionGripperPresenter.Update, so a two-thumb selection ran the whole reposition pass - the ancestor-clip walk behind GripperClipBounds included - twice per rendered frame. Culled grippers kept their subscription too, so the doubling outlived their visibility. Move the loop to the presenter and key it on GripperMode instead of the popups' open state. Bootstrap is unchanged: the subscription was already established from inside Update (via ShowAt), which is the only entry point. CaretWithStemAndThumb no longer needs the reposition callback, nor the Popup.Closed handler that existed only to unsubscribe. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 0c37ee2)
Test fidelity: - The *_Does_Not_Lock_* tests asserted a "did we scroll at all" offset threshold of 100, but the clamp's target was the box's own offset in the content (fillerAbove = 120), so all five passed with the lock in place. They now assert the box is fully outside the viewport. Verified by injecting ChangeView(120) - the clamp's exact result - before the assert: all five fail, and pass again without it. - The straddle test waited on WaitForIdle, which pumps the dispatcher without necessarily producing a rendered frame, so "still showing" could pass on a frame that never ran. It now waits on the gripper's own reported position, and asserts on the thumb ink in the band below the viewport - present while the anchor is inside, gone once culled - so the culling tests no longer only assert the flag Cull() sets. - Selectable TextBlock had no culling coverage despite taking the same ancestor-clipped GripperClipBounds; added the mirror test. - Spelled out the leave-the-viewport assertion in the scroll-away test as an explicit non-intersection check. Hardening: - Contain and report a throw escaping Update: the frame subscription now outlives gripper visibility, so an exception would take the window's render loop with it. - Trace log on the cull transition, naming the clip - an empty one means GripperClipBounds computed nothing rather than the anchor scrolling away. - Note that the clip is an axis-aligned bbox, so rotated ancestors over-approximate. - _popup?.IsOpen is true, per CodeQL. - Restore the files' original absence of a UTF-8 BOM. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 210c358)
An open popup is observable through the public VisualTreeHelper.GetOpenPopupsForXamlRoot, and WinUI exposes nothing of the sort - so a text field the user tapped several scrolls ago should not still be reporting one. Collapsing rather than closing was only needed while the popup drove the per-frame reposition. It doesn't any more: the loop is subscribed by the presenter on the CompositionTarget and keyed on GripperMode, so it keeps ticking with every popup closed and ShowAt reopens on the way back in. Nothing collapses the gripper now, so the visibility half of IsShowing and the explicit re-show in ShowAt both go with it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit e482e77)
StartBringIntoView leaves the offset at 0 on some targets, so the downward drag had nowhere to scroll and the test failed its own premise rather than the behavior it guards - Assert.IsGreaterThan actual <0> expected <200> on iOS Skia Runtime Tests 3, on both the run and the retry. The old assertion (box pinned at the ScrollViewer's bottom edge) tolerated a no-op scroll; the delta assertion does not. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 738a288)
When_Touch_Focused_Then_Scrolled_Away_The_Scroll_Sticks failed on the iOS and Android shards with a mute delta of 0. The cause was not the scroll lock it guards, nor the geometry: it was the selection flyout the test's own setup left open. Measured across all three touch conventions on Skia Desktop, the single discriminator is whether the SelectionFlyout is open. An open light-dismiss flyout puts a window-filling hit-testable overlay above the whole tree (FlyoutBasePopupPanel, transparent Background, IsViewHit => the popup's IsLightDismissEnabled), so a press anywhere is consumed dismissing the flyout rather than reaching the ScrollViewer - and the toolbar itself is placed above the selection, overlapping the viewport, where a press goes to its buttons instead. Both are correct behaviour; they just cost the gesture this test needs. Once the flyout is gone the same drag scrolls the full 470 from either point. The test's second tap is what opened it: on the mobile conventions that tap word-selects and pops the flyout, where the Desktop convention leaves it closed - which is why the desktop shards were green throughout. One tap on a pinned Android convention reaches the state this test is actually about: the insertion handle the removed clamp keyed on, no selection, no flyout. The setup offset is bounded on both sides so the geometry cannot drift into another mute failure, the premises are asserted rather than left implicit, and the failure message carries the caret mode, selection, flyout state and drag geometry - the touch conventions can only be observed on CI, so each half has to say when it is the one that broke. Pinned to SkiaDesktop | SkiaAndroid like every sibling in this cluster (including the _iOS-suffixed one): the convention is pinned in code, so running it on an iOS or WASM host only exercises a combination that never ships. Verified on Skia Desktop: passes; fails with Actual value <-30> when the clamp's effect is injected before the assert, with every premise reporting healthy; no regressions across Given_TextBox + Given_TextBlock (354 passed, 8 skipped, 1 pre-existing master failure in When_Inlines_Transitively_Change). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 4e49157)
2 of 5 tasks
ajpinedam
approved these changes
Aug 27, 2026
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24250/wasm-skia-net9/index.html |
Contributor
|
The build 230677 did not find any UI Test snapshots differences. |
Contributor
Author
|
Tick the box to add this pull request to the merge queue (same as
|
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.
GitHub Issue: Tracked internally — no public issue for this one.
PR Type:
🐞 Bugfix
What changed? 🚀
Current behavior. While a TextBox held a live touch caret — the Android insertion handle, or a full touch selection — an enclosing
ScrollViewerrefused to scroll away from it.ScrollViewer.ClampOffsetsToFocusedTextBoxrewrote the offset back onto the TextBox after every scroll, andScrollContentPresenterdiscarded touch inertia outright to make the clamp land. The user-visible result was a form that could not be scrolled past the field they had just tapped.That clamp existed to hide a different defect: the selection grippers are drawn in a popup that no
ScrollViewerclips, so once the TextBox scrolled out of view they kept painting at their old screen position — over the app's status/nav bar, or over whatever the scroll had moved under them. Pinning the scroll meant the TextBox could never leave the viewport, so the grippers never got the chance to strand.This PR removes the scroll lock and fixes the gripper problem where it belongs:
TextSelectionGripperPresenter.Updatenow culls each gripper against the host's ancestor-clipped bounds (GetGlobalBoundsWithOptions(ignoreClipping: false, …)) rather than its raw bounds. A TextBox scrolled out of an enclosingScrollViewerstill has valid raw bounds, which is why the old test passed while the grippers stranded.Editor.HandleView.isPositionVisible). The probe is a 1px rect rather than a bare point, because both sides of the test come from float matrices and a caret line ending flush with the clip (a selectableTextBlock's last line) must not flicker on rounding.ShowAtreopens it when the anchor scrolls back into view. That is only safe because the per-frame reposition is driven by a single presenter-levelCompositionTarget.FrameRenderedsubscription keyed on the gripper mode — not by the popups, and not once per showing gripper — so the loop keeps ticking with every popup closed. Leaving them open would report a popup through the publicVisualTreeHelper.GetOpenPopupsForXamlRootthat WinUI never exposes.UIElement.Pointers.ClearPointersStateOnUnload), so culling mid-drag ends the gesture: the remaining moves are dropped and the release never reaches the gripper, leaving the selection toolbar closed too. The accepted cost is a dragged gripper painting outside the clip until the finger lifts; native avoids even that by auto-scrolling the container when a handle reaches the edge, which we don't do.Updateis contained and reported once — the subscription outlives gripper visibility, so it would otherwise take the window's render loop with it. The cull transition logs the anchor and the clip atTrace, so an empty clip (GripperClipBoundscomputing nothing for an out-of-tree or zero-sized host) is distinguishable from the anchor genuinely having scrolled away.ScrollViewer.ShouldSnapToTouchTextBox/ClampOffsetsToFocusedTextBoxand the matching inertia special-case inScrollContentPresenter.Managedare gone. The thumb side length is now a named constant (CaretWithStemAndThumb.ThumbSize) shared by the gripper layout and the culling math, instead of a16repeated in both.internal/private): a focused TextBox with a touch caret no longer pins itsScrollViewer. That is the point of the fix, but it does reverse a previously-asserted behavior.When_Touch_Focused_Then_Scrolled_Awayasserted the TextBox stayed pinned inside itsScrollViewer; it is renamed toWhen_Touch_Focused_Then_Scrolled_Away_The_Scroll_Sticksand now asserts the opposite — the user's scroll sticks and the box is allowed to leave the viewport. The gripper stranding that the old assertion was really protecting against is covered directly instead (see below).Intended behavior, for the record: a focused element is scrolled into view on focus — it is not permanently locked there. A user scroll expresses intent and must always override it. Focus-driven bring-into-view is untouched by this PR and still covered by
When_GotFocus_BringIntoViewandWhen_OuterScrollViewer_BringIntoView_Scrolls_To_Caret.Test coverage
Eight runtime tests in
Given_TextBox.skia.cs(Skia Desktop + Skia Android, for the mobile touch conventions) and one inGiven_TextBlock.cs:When_Touch_Tap_Does_Not_Lock_ScrollViewer_AndroidWhen_Touch_Tap_Empty_Does_Not_Lock_ScrollViewer_AndroidWhen_Touch_Selection_Does_Not_Lock_ScrollViewer_Android/_iOSWhen_Touch_Selection_Flick_Does_Not_Lock_ScrollViewer_AndroidScrollContentPresenterinertia half — the timer tests alone would still pass if inertia stayed hijackedWhen_Scrolled_Out_Of_View_Grippers_Are_HiddenWhen_Caret_Line_Straddles_Viewport_Edge_Grippers_Are_HiddenWhen_Gripper_Dragged_Past_Viewport_Edge_Drag_Keeps_TrackingGiven_TextBlock.When_IsTextSelectionEnabled_Scrolled_Out_Of_View_Then_Hides_GrippersTextBlockhost, which takes the same clip changeThe five
*_Does_Not_Lock_*tests assert the box ended up outside the viewport rather than that the offset cleared a threshold: the old clamp's target was the box's own offset inside the content, which clears any threshold low enough to be safe. Verified by injecting the clamp's exact result (ChangeView(null, 120, …)) immediately before the assert — all five fail, and pass again once it is removed.Two notes for reviewers on test timing. Several tests wait on the scroll-end snap timer (
FeatureConfiguration.ScrollViewer.SnapDelay) plus a margin, since that timer is what the old lock fired from — if any prove flaky on slower CI agents, the waits are the place to look. AndWindowHelper.WaitForIdlepumps the dispatcher without necessarily producing a rendered frame, while culling and repositioning only happen in the per-frameUpdate: tests that depend on either wait on the gripper's own reported position, or put a real delay between injected pointer moves. Back-to-back injected moves never yield to the renderer at all, which silently passed two of these tests before it was caught.Known gaps, tracked separately
Accepted in this PR, so a reviewer doesn't have to re-derive them:
ThumbSize(16px). That is the deliberate rule — native Android probes the same anchor point — andWhen_Caret_Line_Straddles_Viewport_Edge_Grippers_Are_Hiddenasserts that ink is there.GetGlobalBoundsWithOptionsbuilds anSKPathonly to read itsBounds, which costs native Skia ops per clipping ancestor on a per-frame path and loses rotation. It makes this PR cull less, never more, so it is a follow-up rather than a prerequisite — Add a rect-only ancestor clip query instead of building an SKPath in GetGlobalBoundsWithOptions #24163.SelectionFlyoutgets none of this treatment: it is positioned once at show time, so a scroll that doesn't press on the text leaves it parked over unrelated content — Skia: the text SelectionFlyout stays parked on screen when its selection scrolls out of view #24164. Pre-existing, and out of scope here.PR Checklist ✅
Screenshots Compare Test Runresults. — pending first CI run🤖 Generated with Claude Code
This is an automatic backport of pull request #24132 done by [Mergify](https://mergify.com).