Merge "Fix stale EditorInfo upon EditText#setText()" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7c9d3192de
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
// SelectionModifierCursorController depends on textCanBeSelected, which depends on text
|
||||
if (mEditor != null) mEditor.prepareCursorControllers();
|
||||
if (mEditor != null) {
|
||||
// SelectionModifierCursorController depends on textCanBeSelected, which depends on text
|
||||
mEditor.prepareCursorControllers();
|
||||
|
||||
mEditor.maybeFireScheduledRestartInputForSetText();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user