Skip to content

Commit 7b9f09c

Browse files
author
Changwan Ryu
committed
Fix for Japanese keyboards
Japanese keyboards do not finish composition when we restore the deleted text. Then some keyboards call setComposingText([text], 1) again which moves the cursor before the restored text, and some keyboards do not respond at all and therefore later composition change moves the cursor before the restored text. It seems that all the keyboard apps I tested calmly respond to the finishComposingText() call, probably because it gets the call in various situations such as focus loss. BUG=758443 (cherry picked from commit 08ed69a) Change-Id: I752d9d86053a923d7ffc4ef248d088ca991aeae1 Reviewed-on: https://chromium-review.googlesource.com/636107 Commit-Queue: Changwan Ryu <changwan@chromium.org> Reviewed-by: Ted Choc <tedchoc@chromium.org> Reviewed-by: Alexandre Elias <aelias@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#500122} Reviewed-on: https://chromium-review.googlesource.com/656515 Reviewed-by: Changwan Ryu <changwan@chromium.org> Cr-Commit-Position: refs/branch-heads/3202@{#74} Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
1 parent af3eed8 commit 7b9f09c

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

chrome/android/java/src/org/chromium/chrome/browser/omnibox/SpannableAutocompleteEditTextModel.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,11 @@ private void restoreBackspacedText(String diff) {
515515
Editable editable = mDelegate.getEditableText();
516516
editable.append(diff);
517517
decrementBatchEditCount();
518+
if (mBatchEditNestCount == 0) { // only at the outermost batch edit
519+
// crbug.com/758443: Japanese keyboard does not finish composition when we restore
520+
// the deleted text.
521+
super.finishComposingText();
522+
}
518523
}
519524

520525
private boolean setAutocompleteSpan() {

chrome/android/junit/src/org/chromium/chrome/browser/omnibox/AutocompleteEditTextTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.util.AttributeSet;
1818
import android.view.KeyEvent;
1919
import android.view.accessibility.AccessibilityEvent;
20+
import android.view.inputmethod.BaseInputConnection;
2021
import android.view.inputmethod.EditorInfo;
2122
import android.view.inputmethod.InputConnection;
2223
import android.widget.LinearLayout;
@@ -744,7 +745,7 @@ private void internalTestDelete_CommitText() {
744745
if (isUsingSpannableModel()) {
745746
// Pretend that we have deleted 'o' first.
746747
mInOrder.verify(mVerifier).onUpdateSelection(4, 4);
747-
// We restore 'o', and clears autocomplete text instead.
748+
// We restore 'o', and clear autocomplete text instead.
748749
mInOrder.verify(mVerifier).onUpdateSelection(5, 5);
749750
assertTrue(mAutocomplete.isCursorVisible());
750751
// Autocomplete removed.
@@ -778,12 +779,18 @@ private void internalTestDelete_CommitText() {
778779
assertTexts("hello", "");
779780
}
780781

782+
private boolean isComposing() {
783+
return BaseInputConnection.getComposingSpanStart(mAutocomplete.getText())
784+
!= BaseInputConnection.getComposingSpanEnd(mAutocomplete.getText());
785+
}
786+
781787
@Test
782788
@Features(@Features.Register(
783789
value = ChromeFeatureList.SPANNABLE_INLINE_AUTOCOMPLETE, enabled = true))
784790
public void testDelete_SetComposingTextWithSpannableModel() {
785791
// User types "hello".
786792
assertTrue(mInputConnection.setComposingText("hello", 1));
793+
assertTrue(isComposing());
787794
mInOrder.verify(mVerifier).onUpdateSelection(5, 5);
788795
verifyOnPopulateAccessibilityEvent(
789796
AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED, "hello", "", -1, 0, -1, 0, 5);
@@ -806,9 +813,10 @@ public void testDelete_SetComposingTextWithSpannableModel() {
806813
assertTrue(mInputConnection.setComposingText("hell", 1));
807814
// Pretend that we have deleted 'o'.
808815
mInOrder.verify(mVerifier).onUpdateSelection(4, 4);
809-
// We restore 'o', and clear autocomplete text instead.
816+
// We restore 'o', finish composition, and clear autocomplete text instead.
810817
mInOrder.verify(mVerifier).onUpdateSelection(5, 5);
811818
assertTrue(mAutocomplete.isCursorVisible());
819+
assertFalse(isComposing());
812820
// Remove autocomplete.
813821
verifyOnPopulateAccessibilityEvent(
814822
AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED, "hello", "hello world", -1, 5, -1, 6, 0);
@@ -1167,4 +1175,4 @@ private void internalTestFocusInAndSelectAll() {
11671175
}
11681176
mInOrder.verifyNoMoreInteractions();
11691177
}
1170-
}
1178+
}

0 commit comments

Comments
 (0)