From 008af64ccecebb9c63b547c86d97fed1ce0394aa Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 25 Jan 2016 13:29:17 -0800 Subject: [PATCH] Keyboard service doesn't commit the last edit when it's dismissed We were getting the proper values, but we thought we were still composing, so the text was still underlined. Fixes #115 --- packages/flutter/lib/src/material/input.dart | 1 + packages/flutter/lib/src/widgets/editable.dart | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/material/input.dart b/packages/flutter/lib/src/material/input.dart index e26a2dec61d..c0cf1beef8f 100644 --- a/packages/flutter/lib/src/material/input.dart +++ b/packages/flutter/lib/src/material/input.dart @@ -109,6 +109,7 @@ class _InputState extends State { _editableString.selection.end); } else if (!focused && _keyboardHandle.attached) { _keyboardHandle.release(); + _editableString.composing = TextRange.empty; } } diff --git a/packages/flutter/lib/src/widgets/editable.dart b/packages/flutter/lib/src/widgets/editable.dart index 6debfe0904b..945613f0395 100644 --- a/packages/flutter/lib/src/widgets/editable.dart +++ b/packages/flutter/lib/src/widgets/editable.dart @@ -26,10 +26,12 @@ class TextRange { end = position; /// A text range that contains nothing and is not in the text. - const TextRange.empty() + const TextRange._empty() : start = -1, end = -1; + static const TextRange empty = const TextRange._empty(); + /// The index of the first character in the range. final int start; @@ -56,7 +58,7 @@ class EditableString implements KeyboardClient { String text; // The range of text that is still being composed. - TextRange composing = const TextRange.empty(); + TextRange composing = TextRange.empty; /// The range of text that is currently selected. TextRange selection; @@ -124,7 +126,7 @@ class EditableString implements KeyboardClient { // TODO(abarth): Why is |newCursorPosition| always 1? TextRange committedRange = _replaceOrAppend(composing, text); selection = new TextRange.collapsed(committedRange.end); - composing = const TextRange.empty(); + composing = TextRange.empty; onUpdated(); } @@ -161,7 +163,7 @@ class EditableString implements KeyboardClient { } void submit(SubmitAction action) { - composing = const TextRange.empty(); + composing = TextRange.empty; onSubmitted(); } }