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

Commit 7afa67ca authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Clear suggestionSpan reference once popup window is closing.

Clear suggestionSpan reference since it is not necessary once the
suggestion window is closed.

suggestionSpan is kept for identifying the target text region in
onItemClick method.

This CL is a part of groundwork for Bug 15347319 and no user visible
change is intended with this CL.

Change-Id: Ie0edf215a1b90629e280ce09df4fd6f5d95fbb06
parent 3a2d0340
Loading
Loading
Loading
Loading
+22 −9
Original line number Diff line number Diff line
@@ -2707,11 +2707,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 {
@@ -2865,9 +2876,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() {
@@ -3019,7 +3032,7 @@ public class Editor {
                    }
                    mTextView.deleteText_internal(spanUnionStart, spanUnionEnd);
                }
                hide();
                hideWithCleanUp();
                return;
            }

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

@@ -3102,7 +3115,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);
    }
}