diff options
| author | 2015-05-22 14:37:01 +0900 | |
|---|---|---|
| committer | 2015-05-22 14:37:01 +0900 | |
| commit | 7e4fbe03899a2c278ffdf1e36fb4a16dc8cc204c (patch) | |
| tree | 1226e1e02eb8143562c33690dae292c43ac265b6 | |
| parent | 1c86159142aa8b5d582cd53e1d16b874c99d3bc4 (diff) | |
Stop offering "Replace..." when there are no suggestions.
Suggestions in a suggestion span can be empty. When all
suggestion spans don't have any suggestions, we shouldn't
offer to show suggestions.
Bug: 21046505
Change-Id: I48a1e19b176769743ad14c5109e4cb3fc9416393
| -rw-r--r-- | core/java/android/widget/Editor.java | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 4fd85b6ea953..5c58ed0ed24d 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -1806,12 +1806,18 @@ public class Editor { } if (selectionStart == selectionEnd) { // Spans overlap the cursor. - return true; + for (int i = 0; i < suggestionSpans.length; i++) { + if (suggestionSpans[i].getSuggestions().length > 0) { + return true; + } + } + return false; } int minSpanStart = mTextView.getText().length(); int maxSpanEnd = 0; int unionOfSpansCoveringSelectionStartStart = mTextView.getText().length(); int unionOfSpansCoveringSelectionStartEnd = 0; + boolean hasValidSuggestions = false; for (int i = 0; i < suggestionSpans.length; i++) { final int spanStart = spannable.getSpanStart(suggestionSpans[i]); final int spanEnd = spannable.getSpanEnd(suggestionSpans[i]); @@ -1821,11 +1827,16 @@ public class Editor { // The span doesn't cover the current selection start point. continue; } + hasValidSuggestions = + hasValidSuggestions || suggestionSpans[i].getSuggestions().length > 0; unionOfSpansCoveringSelectionStartStart = Math.min(unionOfSpansCoveringSelectionStartStart, spanStart); unionOfSpansCoveringSelectionStartEnd = Math.max(unionOfSpansCoveringSelectionStartEnd, spanEnd); } + if (!hasValidSuggestions) { + return false; + } if (unionOfSpansCoveringSelectionStartStart >= unionOfSpansCoveringSelectionStartEnd) { // No spans cover the selection start point. return false; |