From fd3eff27bdb2592cf398d11c5f2f03ba5170f962 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Mon, 6 Jul 2015 18:20:41 +0900 Subject: [PATCH] Fix: Wrong suggestion popup position in extract mode. Replace text was handled by the original EditText; thus, we couldn't correctly decide popup window position. Also, changing selection range replaces entire text of the extracted EditText. As a result, text cannot be replaced with the selected item when there is a selection. This change is a workaround for this issue. This quits offering "Replace" for selection in extract mode. Bug: 22038802 Change-Id: I052b027cfd10eeb289f77f4c6b228acf58fea636 --- core/java/android/inputmethodservice/ExtractEditText.java | 8 ++++++-- core/java/android/widget/Editor.java | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/java/android/inputmethodservice/ExtractEditText.java b/core/java/android/inputmethodservice/ExtractEditText.java index b039fc7622459..a2c1d1841c207 100644 --- a/core/java/android/inputmethodservice/ExtractEditText.java +++ b/core/java/android/inputmethodservice/ExtractEditText.java @@ -103,8 +103,12 @@ public class ExtractEditText extends EditText { } @Override public boolean onTextContextMenuItem(int id) { - // Select all shouldn't be handled by the original edit text, but by the extracted one. - if (id != android.R.id.selectAll && mIME != null && mIME.onExtractTextContextMenuItem(id)) { + // Select all and Replace text shouldn't be handled by the original edit text, but by the + // extracted one. + if (id == android.R.id.selectAll || id == android.R.id.replaceText) { + return super.onTextContextMenuItem(id); + } + if (mIME != null && mIME.onExtractTextContextMenuItem(id)) { // Mode was started on Extracted, needs to be stopped here. // Cut will change the text, which stops selection mode. if (id == android.R.id.copy || id == android.R.id.paste) stopTextActionMode(); diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index d897f49dbffd5..15d13aeebca85 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -3225,7 +3225,8 @@ public class Editor { } private void updateReplaceItem(Menu menu) { - boolean canReplace = mTextView.isSuggestionsEnabled() && shouldOfferToShowSuggestions(); + boolean canReplace = mTextView.isSuggestionsEnabled() && shouldOfferToShowSuggestions() + && !(mTextView.isInExtractedMode() && mTextView.hasSelection()); boolean replaceItemExists = menu.findItem(TextView.ID_REPLACE) != null; if (canReplace && !replaceItemExists) { menu.add(Menu.NONE, TextView.ID_REPLACE, MENU_ITEM_ORDER_REPLACE,