From f93ea0ead10a2f39d83c778e799fe60228f01f23 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Fri, 29 Apr 2016 14:02:56 -0400 Subject: [PATCH] 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 --- .../flutter/lib/src/widgets/editable.dart | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/flutter/lib/src/widgets/editable.dart b/packages/flutter/lib/src/widgets/editable.dart index 22b1c063b5..7ce0fffa7c 100644 --- a/packages/flutter/lib/src/widgets/editable.dart +++ b/packages/flutter/lib/src/widgets/editable.dart @@ -303,16 +303,16 @@ class RawInputLineState extends ScrollableState { // EditableLineWidget, not just changes triggered by user gestures. requestKeyboard(); + InputValue newInput = new InputValue(text: _keyboardClient.inputValue.text, selection: selection); if (config.onChanged != null) - config.onChanged(_keyboardClient.inputValue.copyWith(selection: selection)); + config.onChanged(newInput); if (_selectionHandles != null) { _selectionHandles.hide(); _selectionHandles = null; } - if (_selectionHandles == null && - _keyboardClient.inputValue.text.isNotEmpty && + if (_keyboardClient.inputValue.text.isNotEmpty && config.selectionHandleBuilder != null) { _selectionHandles = new TextSelectionHandles( selection: selection, @@ -325,8 +325,9 @@ class RawInputLineState extends ScrollableState { } void _handleSelectionHandleChanged(TextSelection selection) { + InputValue newInput = new InputValue(text: _keyboardClient.inputValue.text, selection: selection); 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 @@ -381,10 +382,14 @@ class RawInputLineState extends ScrollableState { else if (_cursorTimer != null && (!focused || !config.value.selection.isCollapsed)) _stopCursorTimer(); - if (_selectionHandles != null && !focused) { - scheduleMicrotask(() { // can't hide while disposing, since it triggers a rebuild - _selectionHandles.hide(); - _selectionHandles = null; + if (_selectionHandles != null) { + scheduleMicrotask(() { // can't update while disposing, since it triggers a rebuild + if (focused) { + _selectionHandles.update(config.value.selection); + } else { + _selectionHandles.hide(); + _selectionHandles = null; + } }); }