From c99d33fb4dcf332b66281a0a6a31710407fc829d Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 28 Feb 2013 16:39:47 -0800 Subject: [PATCH 1/2] Actually change the place where updateSelection is called Call updateSelection in endBatchEdit instead of onDraw. This works because all edits go through a batch edit, which is already the case although the next change will enforce it going forward. This is step 3 of a four-step refactoring. Bug: 8000119 Change-Id: Ia5e257382e2ef2168726bf3d9c7c84f9379ba376 --- core/java/android/widget/Editor.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 8f90fa5496de6..5848f1f396821 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -1085,9 +1085,12 @@ public class Editor { mTextView.updateAfterEdit(); reportExtractedText(); } else if (ims.mCursorChanged) { - // Cheezy way to get us to report the current cursor location. + // Cheesy way to get us to report the current cursor location. mTextView.invalidateCursor(); } + // sendUpdateSelection knows to avoid sending if the selection did + // not actually change. + sendUpdateSelection(); } static final int EXTRACT_NOTHING = -2; @@ -1221,6 +1224,8 @@ public class Editor { candStart = EditableInputConnection.getComposingSpanStart(sp); candEnd = EditableInputConnection.getComposingSpanEnd(sp); } + // InputMethodManager#updateSelection skips sending the message if + // none of the parameters have changed since the last time we called it. imm.updateSelection(mTextView, selectionStart, selectionEnd, candStart, candEnd); } @@ -1244,11 +1249,6 @@ public class Editor { // input method. reported = reportExtractedText(); } - if (!reported && highlight != null) { - // TODO: stop doing this here, and do it after each change - // as needed instead. - sendUpdateSelection(); - } } if (imm.isWatchingCursor(mTextView) && highlight != null) { From aaf8671c439670f0a72401379431ddd72ff368c4 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 1 Mar 2013 15:08:14 -0800 Subject: [PATCH 2/2] Final small cleanup. This does not change anything in the practice since the only time where timing of the endBatchEdit() call matters is when sendCurrentText is a no-op. Still, it's theoretically correct to do it in this order. This concludes a four-step refactoring moving where the editor calls updateSelection to warn the IME of a cursor move. Change-Id: I3109a482ec1d4cd9b4ffb33cc363a4ce5128861a --- core/java/android/view/inputmethod/BaseInputConnection.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/inputmethod/BaseInputConnection.java b/core/java/android/view/inputmethod/BaseInputConnection.java index 7ec53980876be..b3ff54d0b5c83 100644 --- a/core/java/android/view/inputmethod/BaseInputConnection.java +++ b/core/java/android/view/inputmethod/BaseInputConnection.java @@ -268,8 +268,9 @@ public class BaseInputConnection implements InputConnection { if (content != null) { beginBatchEdit(); removeComposingSpans(content); - endBatchEdit(); + // Note: sendCurrentText does nothing unless mDummyMode is set sendCurrentText(); + endBatchEdit(); } return true; } @@ -466,8 +467,9 @@ public class BaseInputConnection implements InputConnection { content.setSpan(COMPOSING, a, b, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING); - endBatchEdit(); + // Note: sendCurrentText does nothing unless mDummyMode is set sendCurrentText(); + endBatchEdit(); } return true; }