Sitelet https://github.com/flutter/flutter/pull/185878
Skip to content

Fix text selection handle drag jumps - #185878

Closed
gabrimatic wants to merge 2 commits into
flutter:masterfrom
gabrimatic:text-selection-handle-scroll-jump-current
Closed

gabrimatic wants to merge 2 commits into
flutter:masterfrom
gabrimatic:text-selection-handle-scroll-jump-current

Conversation

@gabrimatic

Copy link
Copy Markdown
Contributor

Fixes #132047

Selection handle drags kept their handle contact position in global coordinates. When dragging a handle caused the editable to scroll, the next drag update converted that stale global position through the updated transform and could resolve the handle target to a line in the opposite direction, causing the scroll offset to jump.

This keeps the drag contact position and line-center target in the RenderEditable local coordinate space, and ignores candidate updates that move opposite to the handle drag direction.

Tests run:

  • ../../bin/flutter analyze --no-pub lib/src/widgets/text_selection.dart test/widgets/editable_text_test.dart
  • ../../bin/flutter test test/widgets/editable_text_test.dart --plain-name="dragging selection handle upward scrolls multiline field steadily on Apple platforms"
  • ../../bin/flutter test test/widgets/text_selection_test.dart --plain-name="can trigger selection handle drag"

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. labels May 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request transitions text selection handle drag positions to local coordinates, adds logic to prevent selection jumps on Apple platforms, and includes a regression test for steady scrolling. Feedback suggests incorporating the local X coordinate during drag initialization for better accuracy and identifies the new platform-specific offset checks as potentially redundant or logically incorrect for reversed selections.

Comment thread packages/flutter/lib/src/widgets/text_selection.dart Outdated
Comment thread packages/flutter/lib/src/widgets/text_selection.dart
Comment thread packages/flutter/lib/src/widgets/text_selection.dart Outdated
Comment thread packages/flutter/lib/src/widgets/text_selection.dart
@gabrimatic
gabrimatic force-pushed the text-selection-handle-scroll-jump-current branch 2 times, most recently from bf2dcb6 to 2ffff93 Compare May 1, 2026 07:21
@gabrimatic
gabrimatic force-pushed the text-selection-handle-scroll-jump-current branch from 2ffff93 to 9e19212 Compare May 1, 2026 08:38
@Renzo-Olivares

Copy link
Copy Markdown
Contributor

Hi @gabrimatic, thank you for the contribution but I think I will close this PR in favor of #185206 since it was in the queue first and is solving the same issue. If we don't get around to landing the linked fix you can feel free to open a new PR.

While I'm closing this PR, thank you again for putting together this patch and working with us on reviews. The team would gladly welcome future contributions from you!

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

Labels

a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextField scrolling jumps around when dragging text selection handle upwards

2 participants