Loading core/java/android/widget/Editor.java +39 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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(); Loading core/java/android/widget/TextView.java +7 −4 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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(); } } /** Loading Loading
core/java/android/widget/Editor.java +39 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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(); Loading
core/java/android/widget/TextView.java +7 −4 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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(); } } /** Loading