Flutter Framework - Fix PR #185206
The problem
In a Flutter text field, dragging a selection handle could make the text viewport jump or flicker. Dragging the top handle could snap the viewport to the bottom of the selection. The bug was reported in flutter/flutter#132047.
The fix
Skip the caret auto-scroll for drag updates
In EditableTextState.userUpdateTextEditingValue, every selection change scheduled a scroll to the caret. During a handle drag that scroll fought the drag and snapped the viewport back to the opposite, static end of the selection. The fix skips it when the cause is SelectionChangedCause.drag. The viewport is still kept in sync by _bringIntoViewBySelectionState, which keeps the active handle in view.
View the editable text changesCover it with two regression tests
Both tests are in packages/flutter/test/widgets/editable_text_test.dart. "Dragging selection base handle upwards scrolls the viewport" drags the base handle to the start of a 100-line field and checks that the viewport follows it to offset 0. "Mouse drag selection from bottom to top does not snap to extent" drags a mouse selection upwards and checks that the viewport does not snap back to the bottom.
View the regression tests changesLeave a TODO for the larger cleanup
The fix is a special case, because the code has several separate paths that reveal the caret. In review, I changed a follow-up note into a TODO that links flutter/flutter#192595, which tracks consolidating those paths.
View issue #192595Tighten the tests during review
The review went through 25 commits. Reviewers asked for the tests to check their own setup, so both tests now assert that the scroll position is at the maximum extent after jumping to the end of the text.
Outcomes
- Merged
- Pull request in flutter/flutter
- Personal contribution, #185206. Fixes #132047. Approved by two Flutter reviewers and merged through the merge queue.
- 2
- Regression tests added
- Personal contribution, in editable_text_test.dart.
- +100 -1
- Lines changed in 2 files
- Personal contribution: 11 added and 1 removed in editable_text.dart, 89 added in editable_text_test.dart.
- 25
- Commits before merge
- Personal contribution, across the review.
Let's talk
Open to remote full-time and freelance work. I'm based in Tangerang, Indonesia (WIB, UTC+7) and reply within 24 hours.
I also take freelance projects. See freelance work