Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a17d8766 authored by Seigo Nonaka's avatar Seigo Nonaka Committed by Android (Google) Code Review
Browse files

Merge "Clear suggestionSpan reference once popup window is closing."

parents 4008c27a 7afa67ca
Loading
Loading
Loading
Loading
+22 −9
Original line number Diff line number Diff line
@@ -2705,11 +2705,22 @@ public class Editor {
            mIsShowingUp = false;
        }

        private class SuggestionInfo {
        private final class SuggestionInfo {
            int suggestionStart, suggestionEnd; // range of actual suggestion within text
            SuggestionSpan suggestionSpan; // the SuggestionSpan that this TextView represents

            // the SuggestionSpan that this TextView represents
            @Nullable
            SuggestionSpan suggestionSpan;

            int suggestionIndex; // the index of this suggestion inside suggestionSpan
            SpannableStringBuilder text = new SpannableStringBuilder();

            @Nullable
            final SpannableStringBuilder text = new SpannableStringBuilder();

            void clear() {
                suggestionSpan = null;
                text.clear();
            }
        }

        private class SuggestionAdapter extends BaseAdapter {
@@ -2863,9 +2874,11 @@ public class Editor {
            return Math.min(positionY, displayMetrics.heightPixels - height);
        }

        @Override
        public void hide() {
            super.hide();
        private void hideWithCleanUp() {
            for (final SuggestionInfo info : mSuggestionInfos) {
                info.clear();
            }
            hide();
        }

        private boolean updateSuggestions() {
@@ -3017,7 +3030,7 @@ public class Editor {
                    }
                    mTextView.deleteText_internal(spanUnionStart, spanUnionEnd);
                }
                hide();
                hideWithCleanUp();
                return;
            }

@@ -3025,7 +3038,7 @@ public class Editor {
            final int spanEnd = editable.getSpanEnd(suggestionInfo.suggestionSpan);
            if (spanStart < 0 || spanEnd <= spanStart) {
                // Span has been removed
                hide();
                hideWithCleanUp();
                return;
            }

@@ -3100,7 +3113,7 @@ public class Editor {
                mTextView.setCursorPosition_internal(newCursorPosition, newCursorPosition);
            }

            hide();
            hideWithCleanUp();
        }
    }

+26 −5
Original line number Diff line number Diff line
@@ -61,11 +61,13 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2
        final int expectedHighlightTextColor = tmpTp.getColor();
        final float expectedHighlightTextSize = tmpTp.getTextSize();

        // Create and wait until SuggestionsPopupWindow is shown.
        final EditText editText = (EditText) activity.findViewById(R.id.textview);
        final Editor editor = editText.getEditorForTesting();
        assertNotNull(editor);
        activity.runOnUiThread(new Runnable() {

        // Request to show SuggestionsPopupWindow.
        Runnable showSuggestionWindowRunner = new Runnable() {
            @Override
            public void run() {
                SpannableStringBuilder ssb = new SpannableStringBuilder();
                ssb.append(sampleText);
@@ -78,8 +80,7 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2
                Selection.setSelection(editText.getText(), singleWordSpanStart, singleWordSpanEnd);
                editText.onTextContextMenuItem(TextView.ID_REPLACE);
            }
        });
        getInstrumentation().waitForIdleSync();
        };

        // In this test, the SuggestionsPopupWindow looks like
        //   abc def ghi
@@ -91,7 +92,8 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2
        // | DELETE        |
        // -----------------
        // *XX* means that XX is highlighted.
        activity.runOnUiThread(new Runnable() {
        Runnable popupVaridator = new Runnable() {
            @Override
            public void run() {
                Editor.SuggestionsPopupWindow popupWindow =
                        editor.getSuggestionsPopupWindowForTesting();
@@ -155,6 +157,25 @@ public class SuggestionsPopupWindowTest extends ActivityInstrumentationTestCase2
                    assertEquals(multiWordSpanEnd, spanned.getSpanEnd(taSpan[0]));
                }
            }
        };

        // Show the SuggestionWindow and verify the contents.
        activity.runOnUiThread(showSuggestionWindowRunner);
        getInstrumentation().waitForIdleSync();
        activity.runOnUiThread(popupVaridator);

        // Request to hide the SuggestionPopupWindow and wait until it is hidden.
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                editText.setText("");
            }
        });
        getInstrumentation().waitForIdleSync();

        // Show and verify the contents again.
        activity.runOnUiThread(showSuggestionWindowRunner);
        getInstrumentation().waitForIdleSync();
        activity.runOnUiThread(popupVaridator);
    }
}