Skip to content

Fix selecting backwards when involving widget spans#184031

Closed
Renzo-Olivares wants to merge 10000 commits into
flutter:masterfrom
Renzo-Olivares:selectableregion-backwards-selection-widgetspan-fix
Closed

Fix selecting backwards when involving widget spans#184031
Renzo-Olivares wants to merge 10000 commits into
flutter:masterfrom
Renzo-Olivares:selectableregion-backwards-selection-widgetspan-fix

Conversation

@Renzo-Olivares

@Renzo-Olivares Renzo-Olivares commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #166462

Before this change _initSelection would always begin its selection search at index 0, this caused issues when selecting backwards and the children of the selection delegate also contained children. This happens because when we select backwards and always start our selection search at index 0, if our pointer moves backwards from point b to point a and point a is already on index 0 (of a selection container with N selectables), the selection logic will short-circuit early thinking we found the selection, skipping any selectables in between point b and point a.

After this change _initSelection will begin its selection search at the opposite edge if it exists. This fixes the issue because when entering a new selectable, while dragging backwards and updating the end edge, first the selectable will call ensureChildUpdated and synthesize a start edge. Then it processes the end edge event and begins to search for that selection edge, we now start this search at the opposite edge which allows us ensure all items between both edges are visited so we can create a continuous selection.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

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

Labels

a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: animation Animation APIs a: desktop Running on desktop a: text input Entering text in a text field or keyboard related problems CICD Run CI/CD engine flutter/engine related. See also e: labels. f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. f: scrolling Viewports, list views, slivers, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken text selection when selecting backwards from TextSpan into WidgetSpan within SelectionArea