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

Commit 713be06f authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi
Browse files

Fix: Selection is not correctly used for SuggestionsPopup.

This happens because suggestions are gathered based on the
selection after setting the cursor position to the middle
of the user selected range, which means 0-width selection
at that position. As a result, SuggestionsPopup was not
shown when any suggestion spans don't overlap middle point
of the selection.

Bug: 20709442
Change-Id: I3e1cb570f451b4ab14cf36f7da23dc2bd22f4ac8
parent 40fd5fac
Loading
Loading
Loading
Loading
+8 −12
Original line number Diff line number Diff line
@@ -351,9 +351,14 @@ public class Editor {
    }

    void replace() {
        if (mSuggestionsPopupWindow == null) {
            mSuggestionsPopupWindow = new SuggestionsPopupWindow();
        }
        hideCursorAndSpanControllers();
        mSuggestionsPopupWindow.show();

        int middle = (mTextView.getSelectionStart() + mTextView.getSelectionEnd()) / 2;
        Selection.setSelection((Spannable) mTextView.getText(), middle);
        showSuggestions();
    }

    void onAttachedToWindow() {
@@ -2086,7 +2091,7 @@ public class Editor {

                    mShowSuggestionRunnable = new Runnable() {
                        public void run() {
                            showSuggestions();
                            replace();
                        }
                    };
                    // removeCallbacks is performed on every touch
@@ -2227,15 +2232,6 @@ public class Editor {
        mCorrectionHighlighter.highlight(info);
    }

    void showSuggestions() {
        if (mSuggestionsPopupWindow == null) {
            mSuggestionsPopupWindow = new SuggestionsPopupWindow();
        }
        hideCursorAndSpanControllers();
        stopTextActionMode();
        mSuggestionsPopupWindow.show();
    }

    void onScrollChanged() {
        if (mPositionListener != null) {
            mPositionListener.onScrollChanged();
@@ -3420,7 +3416,7 @@ public class Editor {

        @Override
        protected int getTextOffset() {
            return mTextView.getSelectionStart();
            return (mTextView.getSelectionStart() + mTextView.getSelectionStart()) / 2;
        }

        @Override