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

Commit 0c4650b4 authored by Gilles Debunne's avatar Gilles Debunne Committed by Android (Google) Code Review
Browse files

Merge "Cursor does not jump back to its previous position when IME is showed up."

parents dc94eea3 ad8484b3
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -762,8 +762,7 @@ public final class InputMethodManager {
     * {@link #RESULT_UNCHANGED_HIDDEN}, {@link #RESULT_SHOWN}, or
     * {@link #RESULT_HIDDEN}.
     */
    public boolean showSoftInput(View view, int flags,
            ResultReceiver resultReceiver) {
    public boolean showSoftInput(View view, int flags, ResultReceiver resultReceiver) {
        checkFocus();
        synchronized (mH) {
            if (mServedView != view && (mServedView == null
+11 −44
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.os.Handler;
import android.os.Message;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ResultReceiver;
import android.os.SystemClock;
import android.text.BoringLayout;
import android.text.DynamicLayout;
@@ -7243,7 +7242,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        // does not happen in that case (using the arrows on a bluetooth keyboard).
        if (focused && isTextEditable()) {
            final InputMethodManager imm = InputMethodManager.peekInstance();
            if (imm != null) imm.showSoftInput(this, 0, null);
            if (imm != null) imm.showSoftInput(this, 0);
        }
    }

@@ -7327,33 +7326,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
    }

    class CommitSelectionReceiver extends ResultReceiver {
        private final int mPrevStart, mPrevEnd;

        public CommitSelectionReceiver(int prevStart, int prevEnd) {
            super(getHandler());
            mPrevStart = prevStart;
            mPrevEnd = prevEnd;
        }

        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            // If this tap was actually used to show the IMM, leave cursor or selection unchanged
            // by restoring its previous position.
            if (resultCode == InputMethodManager.RESULT_SHOWN) {
                final int len = mText.length();
                int start = Math.min(len, mPrevStart);
                int end = Math.min(len, mPrevEnd);
                Selection.setSelection((Spannable)mText, start, end);

                boolean selectAllGotFocus = mSelectAllOnFocus && mTouchFocusSelected;
                if (hasSelection() && !selectAllGotFocus) {
                    startSelectionActionMode();
                }
            }
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        final int action = event.getActionMasked();
@@ -7394,10 +7366,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                && mText instanceof Spannable && mLayout != null) {
            boolean handled = false;

            // Save previous selection, in case this event is used to show the IME.
            int oldSelStart = getSelectionStart();
            int oldSelEnd = getSelectionEnd();

            final int oldScrollX = mScrollX;
            final int oldScrollY = mScrollY;

@@ -7429,25 +7397,24 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                }

                if (touchIsFinished) {
                    CommitSelectionReceiver csr = null;
                    if (getSelectionStart() != oldSelStart || getSelectionEnd() != oldSelEnd ||
                            didTouchFocusSelect()) {
                        csr = new CommitSelectionReceiver(oldSelStart, oldSelEnd);
                    }

                    // Show the IME, except when selecting in read-only text.
                    if (!mTextIsSelectable) {
                        final InputMethodManager imm = InputMethodManager.peekInstance();
                        handled |= imm != null && imm.showSoftInput(this, 0, csr) && (csr != null);
                        handled |= imm != null && imm.showSoftInput(this, 0);
                    }


                    boolean selectAllGotFocus = mSelectAllOnFocus && didTouchFocusSelect();
                    if (!selectAllGotFocus && hasSelection()) {
                        startSelectionActionMode();
                    } else {
                        stopSelectionActionMode();
                    boolean selectAllGotFocus = mSelectAllOnFocus && mTouchFocusSelected;
                        if (hasInsertionController() && !selectAllGotFocus && mText.length() > 0) {
                            getInsertionController().show();
                        }
                    }
                }
            }

            if (handled) {
                return true;