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

Commit 7c9d3192 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix stale EditorInfo upon EditText#setText()" into sc-dev

parents 469c7c83 a35ebcf8
Loading
Loading
Loading
Loading
+39 −1
Original line number Diff line number Diff line
@@ -259,6 +259,20 @@ public class Editor {
    // Used to highlight a word when it is corrected by the IME
    private CorrectionHighlighter mCorrectionHighlighter;

    /**
     * {@code true} when {@link TextView#setText(CharSequence, TextView.BufferType, boolean, int)}
     * is being executed and {@link InputMethodManager#restartInput(View)} is scheduled to be
     * called.
     *
     * <p>This is also used to avoid an unnecessary invocation of
     * {@link InputMethodManager#updateSelection(View, int, int, int, int)} when
     * {@link InputMethodManager#restartInput(View)} is scheduled to be called already
     * See bug 186582769 for details.</p>
     *
     * <p>TODO(186582769): Come up with better way.</p>
     */
    private boolean mHasPendingRestartInputForSetText = false;

    InputContentType mInputContentType;
    InputMethodState mInputMethodState;

@@ -1825,6 +1839,29 @@ public class Editor {
        }
    }

    /**
     * Called from {@link TextView#setText(CharSequence, TextView.BufferType, boolean, int)} to
     * schedule {@link InputMethodManager#restartInput(View)}.
     */
    void scheduleRestartInputForSetText() {
        mHasPendingRestartInputForSetText = true;
    }

    /**
     * Called from {@link TextView#setText(CharSequence, TextView.BufferType, boolean, int)} to
     * actually call {@link InputMethodManager#restartInput(View)} if it's scheduled.  Does nothing
     * otherwise.
     */
    void maybeFireScheduledRestartInputForSetText() {
        if (mHasPendingRestartInputForSetText) {
            final InputMethodManager imm = getInputMethodManager();
            if (imm != null) {
                imm.restartInput(mTextView);
            }
            mHasPendingRestartInputForSetText = false;
        }
    }

    static final int EXTRACT_NOTHING = -2;
    static final int EXTRACT_UNKNOWN = -1;

@@ -1958,7 +1995,8 @@ public class Editor {
    }

    private void sendUpdateSelection() {
        if (null != mInputMethodState && mInputMethodState.mBatchEditNesting <= 0) {
        if (null != mInputMethodState && mInputMethodState.mBatchEditNesting <= 0
                && !mHasPendingRestartInputForSetText) {
            final InputMethodManager imm = getInputMethodManager();
            if (null != imm) {
                final int selectionStart = mTextView.getSelectionStart();
+7 −4
Original line number Diff line number Diff line
@@ -6285,11 +6285,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                || needEditableForNotification) {
            createEditorIfNeeded();
            mEditor.forgetUndoRedo();
            mEditor.scheduleRestartInputForSetText();
            Editable t = mEditableFactory.newEditable(text);
            text = t;
            setFilters(t, mFilters);
            InputMethodManager imm = getInputMethodManager();
            if (imm != null) imm.restartInput(this);
        } else if (precomputed != null) {
            if (mTextDir == null) {
                mTextDir = getTextDirectionHeuristic();
@@ -6408,8 +6407,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            notifyListeningManagersAfterTextChanged();
        }
        if (mEditor != null) {
            // SelectionModifierCursorController depends on textCanBeSelected, which depends on text
        if (mEditor != null) mEditor.prepareCursorControllers();
            mEditor.prepareCursorControllers();
            mEditor.maybeFireScheduledRestartInputForSetText();
        }
    }
    /**