Commit f93ea0ea authored by Matt Perry's avatar Matt Perry

Clear the composing range when selecting text. (#3635)

This fixes a bug where editing the selected text on Android would delete
the wrong block of text.

BUG=https://github.com/flutter/flutter/issues/3567
parent 60755f6d
...@@ -303,16 +303,16 @@ class RawInputLineState extends ScrollableState<RawInputLine> { ...@@ -303,16 +303,16 @@ class RawInputLineState extends ScrollableState<RawInputLine> {
// EditableLineWidget, not just changes triggered by user gestures. // EditableLineWidget, not just changes triggered by user gestures.
requestKeyboard(); requestKeyboard();
InputValue newInput = new InputValue(text: _keyboardClient.inputValue.text, selection: selection);
if (config.onChanged != null) if (config.onChanged != null)
config.onChanged(_keyboardClient.inputValue.copyWith(selection: selection)); config.onChanged(newInput);
if (_selectionHandles != null) { if (_selectionHandles != null) {
_selectionHandles.hide(); _selectionHandles.hide();
_selectionHandles = null; _selectionHandles = null;
} }
if (_selectionHandles == null && if (_keyboardClient.inputValue.text.isNotEmpty &&
_keyboardClient.inputValue.text.isNotEmpty &&
config.selectionHandleBuilder != null) { config.selectionHandleBuilder != null) {
_selectionHandles = new TextSelectionHandles( _selectionHandles = new TextSelectionHandles(
selection: selection, selection: selection,
...@@ -325,8 +325,9 @@ class RawInputLineState extends ScrollableState<RawInputLine> { ...@@ -325,8 +325,9 @@ class RawInputLineState extends ScrollableState<RawInputLine> {
} }
void _handleSelectionHandleChanged(TextSelection selection) { void _handleSelectionHandleChanged(TextSelection selection) {
InputValue newInput = new InputValue(text: _keyboardClient.inputValue.text, selection: selection);
if (config.onChanged != null) if (config.onChanged != null)
config.onChanged(_keyboardClient.inputValue.copyWith(selection: selection)); config.onChanged(newInput);
} }
/// Whether the blinking cursor is actually visible at this precise moment /// Whether the blinking cursor is actually visible at this precise moment
...@@ -381,10 +382,14 @@ class RawInputLineState extends ScrollableState<RawInputLine> { ...@@ -381,10 +382,14 @@ class RawInputLineState extends ScrollableState<RawInputLine> {
else if (_cursorTimer != null && (!focused || !config.value.selection.isCollapsed)) else if (_cursorTimer != null && (!focused || !config.value.selection.isCollapsed))
_stopCursorTimer(); _stopCursorTimer();
if (_selectionHandles != null && !focused) { if (_selectionHandles != null) {
scheduleMicrotask(() { // can't hide while disposing, since it triggers a rebuild scheduleMicrotask(() { // can't update while disposing, since it triggers a rebuild
_selectionHandles.hide(); if (focused) {
_selectionHandles = null; _selectionHandles.update(config.value.selection);
} else {
_selectionHandles.hide();
_selectionHandles = null;
}
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment