summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Haoyu Zhang <haoyuchang@google.com> 2023-07-29 08:58:51 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-07-29 08:58:51 +0000
commitcda1b3aff43df367acf5672e3a117a17da594514 (patch)
treec8c2b4c91e84888708aafccc3960fa2837308357
parent26c64fa07f0136a22fdfa0068b0cd8cdc57d09b4 (diff)
parent9b1c7530c6b8a5131fa8b90e8fd14ea38e8770b3 (diff)
Merge "Fix: setTransformationMethod in insert mode doesn't working after ag/23164813" into udc-qpr-dev am: 9b1c7530c6
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23924702 Change-Id: I0f309bd4e6826060dbb60ff70e3371a19be1bc0f Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--core/java/android/widget/Editor.java42
1 files changed, 21 insertions, 21 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 3da9e96618f3..f39122a0a5c1 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -8207,7 +8207,8 @@ public class Editor {
*/
void beforeSetText() {
// TextView#setText is called because our call to
- // TextView#setTransformationMethodInternal in enterInsertMode() or exitInsertMode().
+ // TextView#setTransformationMethodInternal in enterInsertMode(), exitInsertMode() or
+ // updateTransformationMethod().
// Do nothing in this case.
if (mUpdatingTransformationMethod) {
return;
@@ -8218,22 +8219,28 @@ public class Editor {
}
/**
- * Notify the {@link InsertModeController} before the TextView's
- * {@link TransformationMethod} is updated. If it's not in the insert mode,
- * the given method is directly returned. Otherwise, it will wrap the given transformation
- * method with an {@link InsertModeTransformationMethod} and then return.
+ * Notify the {@link InsertModeController} that TextView#setTransformationMethod is called.
+ * If it's not in the insert mode, the given transformation method is directly set to the
+ * TextView. Otherwise, it will wrap the given transformation method with an
+ * {@link InsertModeTransformationMethod} and then set it on the TextView.
*
- * @param oldTransformationMethod the new {@link TransformationMethod} to be set on the
+ * @param transformationMethod the new {@link TransformationMethod} to be set on the
* TextView.
- * @return the updated {@link TransformationMethod} to be set on the Textview.
*/
- TransformationMethod updateTransformationMethod(
- TransformationMethod oldTransformationMethod) {
- if (!mIsInsertModeActive) return oldTransformationMethod;
+ void updateTransformationMethod(TransformationMethod transformationMethod) {
+ if (!mIsInsertModeActive) {
+ setTransformationMethod(transformationMethod, /* updateText */ true);
+ return;
+ }
+ // Changing TransformationMethod will reset selection range to [0, 0), we need to
+ // manually restore the old selection range.
+ final int selectionStart = mTextView.getSelectionStart();
+ final int selectionEnd = mTextView.getSelectionEnd();
mInsertModeTransformationMethod = mInsertModeTransformationMethod.update(
- oldTransformationMethod, mTextView.isSingleLine());
- return mInsertModeTransformationMethod;
+ transformationMethod, mTextView.isSingleLine());
+ setTransformationMethod(mInsertModeTransformationMethod, /* updateText */ true);
+ Selection.setSelection((Spannable) mTextView.getText(), selectionStart, selectionEnd);
}
}
@@ -8259,18 +8266,11 @@ public class Editor {
* @param method the {@link TransformationMethod} to be set on the TextView.
*/
void setTransformationMethod(TransformationMethod method) {
- if (mInsertModeController == null || !mInsertModeController.mIsInsertModeActive) {
+ if (mInsertModeController == null) {
mTextView.setTransformationMethodInternal(method, /* updateText */ true);
return;
}
-
- // Changing TransformationMethod will reset selection range to [0, 0), we need to
- // manually restore the old selection range.
- final int selectionStart = mTextView.getSelectionStart();
- final int selectionEnd = mTextView.getSelectionEnd();
- method = mInsertModeController.updateTransformationMethod(method);
- mTextView.setTransformationMethodInternal(method, /* updateText */ true);
- Selection.setSelection((Spannable) mTextView.getText(), selectionStart, selectionEnd);
+ mInsertModeController.updateTransformationMethod(method);
}
/**