diff options
author | Noopur Gupta | 2019-03-06 18:23:02 +0000 |
---|---|---|
committer | Noopur Gupta | 2019-03-06 18:23:02 +0000 |
commit | b0d63d9ce8037c9f304ee2e669621266df54820c (patch) | |
tree | a577a32beb5c229ac18e6092e69d6109445ab789 | |
parent | dd94c4b6d3b87eb57d89f2afa3ef4dc7b96e8488 (diff) | |
download | eclipse.platform.text-R4_11_maintenance.tar.gz eclipse.platform.text-R4_11_maintenance.tar.xz eclipse.platform.text-R4_11_maintenance.zip |
Revert "Bug 541404 - improve UndoableCompoundTextChange with single change"Y20190320-2200Y20190319-2305Y20190316-1220Y20190313-2200Y20190313-0215Y20190308-0715Y20190307-1015Y20190306-2200S4_11_0_RC2R4_11I20190307-0500I20190306-2135I20190306-1800R4_11_maintenance
This reverts commit dd94c4b6d3b87eb57d89f2afa3ef4dc7b96e8488.
Change-Id: Ibee48390dd5f4c0a2b580972a4f7f1d2ccfdcd3f
-rw-r--r-- | org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java | 110 |
1 files changed, 38 insertions, 72 deletions
diff --git a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java index ec9e8ce3272..57e3f925e4f 100644 --- a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java +++ b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java @@ -141,13 +141,12 @@ public class DocumentUndoManager implements IDocumentUndoManager { */ protected void undoTextChange() { try { - if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4) { + if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4) ((IDocumentExtension4) fDocumentUndoManager.fDocument).replace(fStart, fText .length(), fPreservedText, fUndoModificationStamp); - } else { + else fDocumentUndoManager.fDocument.replace(fStart, fText.length(), fPreservedText); - } } catch (BadLocationException x) { } } @@ -269,11 +268,10 @@ public class DocumentUndoManager implements IDocumentUndoManager { */ protected void redoTextChange() { try { - if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4) { + if (fDocumentUndoManager.fDocument instanceof IDocumentExtension4) ((IDocumentExtension4) fDocumentUndoManager.fDocument).replace(fStart, fEnd - fStart, fText, fRedoModificationStamp); - } else { + else fDocumentUndoManager.fDocument.replace(fStart, fEnd - fStart, fText); - } } catch (BadLocationException x) { } } @@ -316,9 +314,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { * @return a new, uncommitted text change or a compound text change */ protected UndoableTextChange createCurrent() { - if (fDocumentUndoManager.fFoldingIntoCompoundChange) { + if (fDocumentUndoManager.fFoldingIntoCompoundChange) return new UndoableCompoundTextChange(fDocumentUndoManager); - } return new UndoableTextChange(fDocumentUndoManager); } @@ -456,7 +453,7 @@ public class DocumentUndoManager implements IDocumentUndoManager { UndoableTextChange c; c= fChanges.get(0); - fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo, DocumentUndoEvent.ABOUT_TO_UNDO, size > 1); + fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo, DocumentUndoEvent.ABOUT_TO_UNDO, true); for (int i= size - 1; i >= 0; --i) { c= fChanges.get(i); @@ -464,7 +461,7 @@ public class DocumentUndoManager implements IDocumentUndoManager { } fDocumentUndoManager.resetProcessChangeState(); fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo, - DocumentUndoEvent.UNDONE, size > 1); + DocumentUndoEvent.UNDONE, true); } return Status.OK_STATUS; } @@ -477,14 +474,14 @@ public class DocumentUndoManager implements IDocumentUndoManager { UndoableTextChange c; c= fChanges.get(size - 1); - fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.ABOUT_TO_REDO, size > 1); + fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.ABOUT_TO_REDO, true); for (int i= 0; i <= size - 1; ++i) { c= fChanges.get(i); c.redoTextChange(); } fDocumentUndoManager.resetProcessChangeState(); - fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.REDONE, size > 1); + fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.REDONE, true); } return Status.OK_STATUS; @@ -512,9 +509,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { @Override protected UndoableTextChange createCurrent() { - if (!fDocumentUndoManager.fFoldingIntoCompoundChange) { + if (!fDocumentUndoManager.fFoldingIntoCompoundChange) return new UndoableTextChange(fDocumentUndoManager); - } reinitialize(); return this; @@ -523,9 +519,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { @Override protected void commit() { // if there is pending data, update the text change - if (fStart > -1) { + if (fStart > -1) updateTextChange(); - } fDocumentUndoManager.fCurrent= createCurrent(); fDocumentUndoManager.resetProcessChangeState(); } @@ -537,24 +532,22 @@ public class DocumentUndoManager implements IDocumentUndoManager { @Override protected long getUndoModificationStamp() { - if (fStart > -1) { + if (fStart > -1) return super.getUndoModificationStamp(); - } else if (fChanges.size() > 0) { + else if (fChanges.size() > 0) return fChanges.get(0) .getUndoModificationStamp(); - } return fUndoModificationStamp; } @Override protected long getRedoModificationStamp() { - if (fStart > -1) { + if (fStart > -1) return super.getRedoModificationStamp(); - } else if (fChanges.size() > 0) { + else if (fChanges.size() > 0) return fChanges.get(fChanges.size() - 1) .getRedoModificationStamp(); - } return fRedoModificationStamp; } @@ -588,9 +581,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { // top operation but changes state. IUndoableOperation op= fHistory.getUndoOperation(fUndoContext); boolean wasValid= false; - if (op != null) { + if (op != null) wasValid= op.canUndo(); - } // Process the change, providing the before and after timestamps processChange(event.getOffset(), event.getOffset() + event.getLength(), event.getText(), fReplacedText, @@ -606,9 +598,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { // created, then we should // notify the history that the current operation changed if its // validity has changed. - if (wasValid != fCurrent.isValid()) { + if (wasValid != fCurrent.isValid()) fHistory.operationChanged(op); - } } else { // if the change created a new fCurrent that we did not yet add // to the @@ -790,9 +781,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { // single document change. if (fLastAddedTextEdit != fCurrent) { fCurrent.pretendCommit(); - if (fCurrent.isValid()) { + if (fCurrent.isValid()) addToOperationHistory(fCurrent); - } } fCurrent.commit(); } @@ -820,16 +810,14 @@ public class DocumentUndoManager implements IDocumentUndoManager { */ @Override public void redo() throws ExecutionException { - if (isConnected() && redoable()) { + if (isConnected() && redoable()) OperationHistoryFactory.getOperationHistory().redo(getUndoContext(), null, null); - } } @Override public void undo() throws ExecutionException { - if (undoable()) { + if (undoable()) OperationHistoryFactory.getOperationHistory().undo(fUndoContext, null, null); - } } @Override @@ -837,9 +825,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { if (!isConnected()) { initialize(); } - if (!fConnected.contains(client)) { + if (!fConnected.contains(client)) fConnected.add(client); - } } @Override @@ -937,9 +924,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { * Initializes the undo history. */ private void initializeUndoHistory() { - if (fHistory != null && fUndoContext != null) { + if (fHistory != null && fUndoContext != null) fHistory.dispose(fUndoContext, true, true, false); - } } @@ -953,9 +939,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { */ private boolean isWhitespaceText(String text) { - if (text == null || text.length() == 0) { + if (text == null || text.length() == 0) return false; - } String[] delimiters= fDocument.getLegalLineDelimiters(); int index= TextUtilities.startsWith(delimiters, text); @@ -964,9 +949,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { int length= text.length(); for (int i= delimiters[index].length(); i < length; i++) { c= text.charAt(i); - if (c != ' ' && c != '\t') { + if (c != ' ' && c != '\t') return false; - } } return true; } @@ -999,21 +983,16 @@ public class DocumentUndoManager implements IDocumentUndoManager { final long afterChangeModificationStamp) { if (insertedText == null) - { insertedText= ""; //$NON-NLS-1$ - } if (replacedText == null) - { replacedText= ""; //$NON-NLS-1$ - } int length= insertedText.length(); int diff= modelEnd - modelStart; - if (fCurrent.fUndoModificationStamp == IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP) { + if (fCurrent.fUndoModificationStamp == IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; - } // normalize if (diff < 0) { @@ -1030,31 +1009,26 @@ public class DocumentUndoManager implements IDocumentUndoManager { || (modelStart != fCurrent.fStart + fTextBuffer.length())) { fCurrent.fRedoModificationStamp= beforeChangeModificationStamp; - if (fCurrent.attemptCommit()) { + if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; - } fInserting= true; } - if (fCurrent.fStart < 0) { + if (fCurrent.fStart < 0) fCurrent.fStart= fCurrent.fEnd= modelStart; - } - if (length > 0) { + if (length > 0) fTextBuffer.append(insertedText); - } } else if (length > 0) { // by pasting or model manipulation fCurrent.fRedoModificationStamp= beforeChangeModificationStamp; - if (fCurrent.attemptCommit()) { + if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; - } fCurrent.fStart= fCurrent.fEnd= modelStart; fTextBuffer.append(insertedText); fCurrent.fRedoModificationStamp= afterChangeModificationStamp; - if (fCurrent.attemptCommit()) { + if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= afterChangeModificationStamp; - } } } else { @@ -1094,9 +1068,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { // either DEL or backspace for the first time fCurrent.fRedoModificationStamp= beforeChangeModificationStamp; - if (fCurrent.attemptCommit()) { + if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; - } // as we can not decide whether it was DEL or backspace // we initialize for backspace @@ -1110,9 +1083,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { } else if (length > 0) { // whereby selection is not empty fCurrent.fRedoModificationStamp= beforeChangeModificationStamp; - if (fCurrent.attemptCommit()) { + if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; - } fCurrent.fStart= modelStart; fCurrent.fEnd= modelEnd; @@ -1132,16 +1104,14 @@ public class DocumentUndoManager implements IDocumentUndoManager { || (modelStart != fCurrent.fStart + fTextBuffer.length())) { fCurrent.fRedoModificationStamp= beforeChangeModificationStamp; - if (fCurrent.attemptCommit()) { + if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; - } fOverwriting= true; } - if (fCurrent.fStart < 0) { + if (fCurrent.fStart < 0) fCurrent.fStart= modelStart; - } fCurrent.fEnd= modelEnd; fTextBuffer.append(insertedText); @@ -1152,9 +1122,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { } // because of typing or pasting whereby selection is not empty fCurrent.fRedoModificationStamp= beforeChangeModificationStamp; - if (fCurrent.attemptCommit()) { + if (fCurrent.attemptCommit()) fCurrent.fUndoModificationStamp= beforeChangeModificationStamp; - } fCurrent.fStart= modelStart; fCurrent.fEnd= modelEnd; @@ -1214,9 +1183,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { * clients, <code>false</code> if it is not */ boolean isConnected() { - if (fConnected == null) { + if (fConnected == null) return false; - } return !fConnected.isEmpty(); } @@ -1241,9 +1209,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { } IUndoableOperation op= OperationHistoryFactory.getOperationHistory().getUndoOperation(getUndoContext()); - if (op != null && !(op instanceof UndoableTextChange)) { + if (op != null && !(op instanceof UndoableTextChange)) return; - } // Record the transfer itself as an undoable change. // If the transfer results from some open operation, recording this change will @@ -1255,9 +1222,8 @@ public class DocumentUndoManager implements IDocumentUndoManager { cmd.fText= cmd.fPreservedText= ""; //$NON-NLS-1$ if (fDocument instanceof IDocumentExtension4) { cmd.fRedoModificationStamp= ((IDocumentExtension4)fDocument).getModificationStamp(); - if (op != null) { + if (op != null) cmd.fUndoModificationStamp= ((UndoableTextChange)op).fRedoModificationStamp; - } } addToOperationHistory(cmd); } |