Commit 12d34bdf authored by Changwan Ryu's avatar Changwan Ryu Committed by Commit Bot

Fix performEditorAction to commit autocomplete text in batch edits

The commitAutocomplete logic was assuming that the autocomplete span
was present and was trying to commit it, but when between onBeginImeCommand
/ onEndImeCommand, we have removed the span in onBeginImeCommand(), so
there is nothing to commit. We just need to commit the text, which does
not interfere with onEndImeCommand() logic.

BUG=810704

Change-Id: Iec7928d2154b6f4c4c8c6197293b6c84fde828f5
Reviewed-on: https://chromium-review.googlesource.com/1020064Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Changwan Ryu <changwan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553393}
parent 1a0a2bf5
...@@ -517,13 +517,22 @@ public class SpannableAutocompleteEditTextModel implements AutocompleteEditTextM ...@@ -517,13 +517,22 @@ public class SpannableAutocompleteEditTextModel implements AutocompleteEditTextM
public void commitAutocomplete() { public void commitAutocomplete() {
if (DEBUG) Log.i(TAG, "commitAutocomplete"); if (DEBUG) Log.i(TAG, "commitAutocomplete");
if (!hasAutocomplete()) return; if (!hasAutocomplete()) return;
String autocompleteText = mCurrentState.getAutocompleteText();
mCurrentState.commitAutocompleteText(); mCurrentState.commitAutocompleteText();
// Invalidate mPreviouslySetState. // Invalidate mPreviouslySetState.
mPreviouslySetState.copyFrom(mCurrentState); mPreviouslySetState.copyFrom(mCurrentState);
mLastEditWasTyping = false; mLastEditWasTyping = false;
incrementBatchEditCount(); // avoids additional notifyAutocompleteTextStateChanged()
mSpanCursorController.commitSpan(); if (mBatchEditNestCount == 0) {
decrementBatchEditCount(); incrementBatchEditCount(); // avoids additional notifyAutocompleteTextStateChanged()
mSpanCursorController.commitSpan();
decrementBatchEditCount();
} else {
// We have already removed span in the onBeginImeCommand(), just append the text.
mDelegate.append(autocompleteText);
}
} }
@Override @Override
......
...@@ -1260,4 +1260,46 @@ public class AutocompleteEditTextTest { ...@@ -1260,4 +1260,46 @@ public class AutocompleteEditTextTest {
assertEquals("abcde", mAutocomplete.getTextWithAutocomplete()); assertEquals("abcde", mAutocomplete.getTextWithAutocomplete());
assertEquals("abcde", mAutocomplete.getTextWithoutAutocomplete()); assertEquals("abcde", mAutocomplete.getTextWithoutAutocomplete());
} }
// crbug.com/810704
@Test
@EnableFeatures(ChromeFeatureList.SPANNABLE_INLINE_AUTOCOMPLETE)
public void testPerformEditorAction() {
// User types "goo".
assertTrue(mInputConnection.setComposingText("goo", 1));
assertTrue(mAutocomplete.shouldAutocomplete());
mAutocomplete.setAutocompleteText("goo", "gle.com");
assertEquals("google.com", mAutocomplete.getText().toString());
// User presses 'GO' key on the keyboard.
assertTrue(mInputConnection.commitText("goo", 1));
assertEquals("google.com", mAutocomplete.getText().toString());
assertTrue(mInputConnection.performEditorAction(EditorInfo.IME_ACTION_GO));
assertEquals("google.com", mAutocomplete.getText().toString());
}
// crbug.com/810704
@Test
@EnableFeatures(ChromeFeatureList.SPANNABLE_INLINE_AUTOCOMPLETE)
public void testPerformEditorActionInBatchEdit() {
// User types "goo".
assertTrue(mInputConnection.setComposingText("goo", 1));
assertTrue(mAutocomplete.shouldAutocomplete());
mAutocomplete.setAutocompleteText("goo", "gle.com");
assertEquals("google.com", mAutocomplete.getText().toString());
// User presses 'GO' key on the keyboard.
mInputConnection.beginBatchEdit();
assertTrue(mInputConnection.commitText("goo", 1));
assertEquals("google.com", mAutocomplete.getText().toString());
assertTrue(mInputConnection.performEditorAction(EditorInfo.IME_ACTION_GO));
assertEquals("google.com", mAutocomplete.getText().toString());
mInputConnection.endBatchEdit();
assertEquals("google.com", mAutocomplete.getText().toString());
}
} }
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