Fix: Undo for drag and drop.
Drag and drop operation can be merged with last edit
operation. In this case, insert and delete were recorded as
independent operations even if they were done in one batch
edit.
With this CL, we always create dedicated undo/redo state for
drag and drop.
Bug: 28588666
Bug: 30297308
Bug: 29871372
Change-Id: Ib4cb144c6b9b5aa095bc9208fcdedaa737964126
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index e0a81dd..b03c984 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -2271,7 +2271,7 @@
}
mCorrectionHighlighter.highlight(info);
- mUndoInputFilter.onCommitCorrection();
+ mUndoInputFilter.freezeLastEdit();
}
void onScrollChanged() {
@@ -2404,6 +2404,7 @@
}
mTextView.beginBatchEdit();
+ mUndoInputFilter.freezeLastEdit();
try {
final int offset = mTextView.getOffsetForPosition(event.getX(), event.getY());
Object localState = event.getLocalState();
@@ -2453,6 +2454,7 @@
}
} finally {
mTextView.endBatchEdit();
+ mUndoInputFilter.freezeLastEdit();
}
}
@@ -5769,7 +5771,7 @@
return null;
}
- void onCommitCorrection() {
+ void freezeLastEdit() {
mEditor.mUndoManager.beginUpdate("Edit text");
EditOperation lastEdit = getLastEdit();
if (lastEdit != null) {
@@ -5830,7 +5832,6 @@
// Add this as the first edit.
if (DEBUG_UNDO) Log.d(TAG, "filter: adding first op " + edit);
um.addOperation(edit, UndoManager.MERGE_MODE_NONE);
- mPreviousOperationWasInSameBatchEdit = mIsUserEdit;
} else if (mergeMode == MERGE_EDIT_MODE_FORCE_MERGE) {
// Forced merges take priority because they could be the result of a non-user-edit
// change and this case should not create a new undo operation.
@@ -5842,7 +5843,6 @@
if (DEBUG_UNDO) Log.d(TAG, "non-user edit, new op " + edit);
um.commitState(mEditor.mUndoOwner);
um.addOperation(edit, UndoManager.MERGE_MODE_NONE);
- mPreviousOperationWasInSameBatchEdit = mIsUserEdit;
} else if (mergeMode == MERGE_EDIT_MODE_NORMAL && lastEdit.mergeWith(edit)) {
// Merge succeeded, nothing else to do.
if (DEBUG_UNDO) Log.d(TAG, "filter: merge succeeded, created " + lastEdit);
@@ -5851,8 +5851,8 @@
if (DEBUG_UNDO) Log.d(TAG, "filter: merge failed, adding " + edit);
um.commitState(mEditor.mUndoOwner);
um.addOperation(edit, UndoManager.MERGE_MODE_NONE);
- mPreviousOperationWasInSameBatchEdit = mIsUserEdit;
}
+ mPreviousOperationWasInSameBatchEdit = mIsUserEdit;
um.endUpdate();
}