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

Fix: stop auto-scrolling during selection handle drag - #185206

Merged
auto-submit[bot] merged 25 commits into
flutter:masterfrom
nicolinx:fix143479
Sep 25, 2026
Merged

auto-submit[bot] merged 25 commits into
flutter:masterfrom
nicolinx:fix143479

Conversation

@nicolinx

@nicolinx nicolinx commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

This PR prevents the text viewport from jumping or "flickering" while a user is dragging selection handles. By disabling automated scrolling during a drag, the viewport remains stable and avoids incorrectly snapping to the bottom of the selection when the user is dragging the top handle.

Fixes #132047

Included a regression test in packages/flutter/test/widgets/editable_text_test.dart to verify that the scroll offset remains stable during a selection drag.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@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 Apr 17, 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 modifies EditableText to prevent automatic scrolling to the caret when a selection change is caused by a drag. Review feedback indicates that the accompanying regression test will fail because it relies on the now-disabled scrolling logic when calling userUpdateTextEditingValue directly. It is recommended to update the test to use simulated drag gestures to verify the viewport's behavior.

Comment thread packages/flutter/lib/src/widgets/editable_text.dart Outdated
Comment thread packages/flutter/test/widgets/editable_text_test.dart Outdated
Comment thread packages/flutter/test/widgets/editable_text_test.dart
@justinmc
justinmc requested a review from Renzo-Olivares April 21, 2026 22:21

@Renzo-Olivares Renzo-Olivares 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.

Hi @nicolinx, thank you for your contribution! This is definitely a worthwhile fix we want to land! I left a few comments regarding testing and my thoughts on the approach.

Comment thread packages/flutter/lib/src/widgets/editable_text.dart Outdated
Comment thread packages/flutter/lib/src/widgets/editable_text.dart Outdated
Comment thread packages/flutter/test/widgets/editable_text_test.dart Outdated
@Renzo-Olivares Renzo-Olivares added CICD Run CI/CD waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds labels Apr 28, 2026
@github-actions github-actions Bot removed CICD Run CI/CD waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds labels Apr 30, 2026
@nicolinx

Copy link
Copy Markdown
Contributor Author

Hi @Renzo-Olivares, thanks for the detailed feedback! I've addressed everything and added the new mouse drag test. Ready for another review.

Comment thread packages/flutter/test/widgets/editable_text_test.dart Outdated
@nicolinx

nicolinx commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Renzo-Olivares, I've updated both tests to use TestWidgetsApp and TestTextField. (I also swapped out the ScrollController for the internal ScrollableState since TestTextField doesn't take a controller parameter). It's ready for another review. Thank you!

@justinmc
justinmc requested a review from Renzo-Olivares May 5, 2026 22:34
@LongCatIsLooong LongCatIsLooong added the CICD Run CI/CD label May 14, 2026
Comment thread packages/flutter/test/widgets/editable_text_test.dart Outdated
Comment thread packages/flutter/test/widgets/editable_text_test.dart

@Renzo-Olivares Renzo-Olivares 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.

Thank you for the changes @nicolinx. Left a few more comments mainly around testing.

Comment thread packages/flutter/test/widgets/editable_text_test.dart Outdated
@Renzo-Olivares Renzo-Olivares added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label May 16, 2026
@github-actions github-actions Bot added p: material_ui material_ui package in flutter/packages p: cupertino_ui cupertino_ui package in flutter/packages and removed CICD Run CI/CD waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds labels May 16, 2026
@nicolinx

Copy link
Copy Markdown
Contributor Author

Hi @Renzo-Olivares , thank you for the feedback. I have addressed all the comments and it's ready for another look. Thank you!

@Renzo-Olivares Renzo-Olivares 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.

Hi @nicolinx, thanks for the quick changes. Left a few more comments about the tests.

Comment thread packages/flutter/test/cupertino/text_field_test.dart Outdated
Comment thread packages/flutter/test/material/text_field_test.dart Outdated

// Populate the viewport and scroll to the bottom to prepare for an upward drag.
scrollable.position.jumpTo(scrollable.position.maxScrollExtent);
await tester.pumpAndSettle();

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.

nit: verify the scroll position after jumping to the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done as well. Added the verification check right after jumping to the end in the same commit.

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.

I think this comment still needs to be addressed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry I missed this part. I've added a verification check to verify the scroll position is at the max scroll extent after jumping.

@Renzo-Olivares Renzo-Olivares added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label May 19, 2026
@nicolinx

Copy link
Copy Markdown
Contributor Author

Hi @Renzo-Olivares. I have addressed all the comments and it's ready for another look. Thank you!

@github-actions github-actions Bot removed the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label May 21, 2026
final int lastWordOffset = controller.text.length - 5;
final Offset lastWordPos = textOffsetToPosition(tester, lastWordOffset);
await tester.longPressAt(lastWordPos, pointer: 7);
await tester.pumpAndSettle();

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.

nit: consider verifying the last word is actually selected after the pumpAndSettle.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Added verification that the last word is selected after pumpAndSettle.

final int lastWordOffset = controller.text.length - 5;
final Offset lastWordPos = textOffsetToPosition(tester, lastWordOffset);
await tester.longPressAt(lastWordPos, pointer: 7);
await tester.pumpAndSettle();

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done as well.


// Populate the viewport and scroll to the bottom to prepare for an upward drag.
scrollable.position.jumpTo(scrollable.position.maxScrollExtent);
await tester.pumpAndSettle();

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.

I think this comment still needs to be addressed.


// Scroll to the bottom of the long text.
scrollable.position.jumpTo(scrollable.position.maxScrollExtent);
await tester.pumpAndSettle();

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.

nit: verify the scroll position after jumping to the end.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Added a verification check to verify the scroll position is at the max scroll extent after jumping.

// (called via _formatAndSetValue), which ensures the active handle is kept in view.
// Bypassing the default caret auto-scroll here prevents conflicts that would snap
// the viewport back to the opposite, static selection end.
// Follow up work: https://github.com/flutter/flutter/issues/192595

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.

Consider changing follow up comment to todo:

// TODO(Renzo-Olivares): Remove this special case once the caret reveal paths are
// consolidated, https://github.com/flutter/flutter/issues/192595.

Renzo-Olivares
Renzo-Olivares previously approved these changes Sep 24, 2026

@Renzo-Olivares Renzo-Olivares 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.

LGTM modulo small comment, thank you for your patience on this one!

@nicolinx

Copy link
Copy Markdown
Contributor Author

LGTM modulo small comment, thank you for your patience on this one!

Sure! I have updated the comment as requested. Please take another look.
Thanks!

@dkwingsmt dkwingsmt added the CICD Run CI/CD label Sep 24, 2026
@Renzo-Olivares Renzo-Olivares removed Decoupling: Not ready to port yet Instructions will be provided when this is ready to move to flutter/packages. Decoupling: Split PR The PR will need to be split to separate Material & Cupertino changes labels Sep 24, 2026

@Renzo-Olivares Renzo-Olivares 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.

LGTM, thank you for the contribution!

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 24, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Sep 25, 2026
Merged via the queue into flutter:master with commit c4ed827 Sep 25, 2026
30 of 31 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 25, 2026
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 CICD Run CI/CD 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

8 participants