Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-08-02 17:00:19 +0000
committerPaul Pazderski2019-08-05 07:26:36 +0000
commit33b7dfb9416086a6c58115ee7a08eb532a502c0c (patch)
tree59b1e30d9187216ce9eb1c58ab9fd976d3df89e1 /org.eclipse.text
parent897119b0f781a958e87bb8441d85acb3ccd910b5 (diff)
downloadeclipse.platform.text-33b7dfb9416086a6c58115ee7a08eb532a502c0c.tar.gz
eclipse.platform.text-33b7dfb9416086a6c58115ee7a08eb532a502c0c.tar.xz
eclipse.platform.text-33b7dfb9416086a6c58115ee7a08eb532a502c0c.zip
Bug 549755 - Use DocumentRewriteSession for undo/redo with many changes
Change-Id: Iac91b58513b265b43be3bb988a78684b140cc10e Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
Diffstat (limited to 'org.eclipse.text')
-rw-r--r--org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java29
1 files changed, 27 insertions, 2 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 4794b626eee..2e803c272a8 100644
--- a/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
+++ b/org.eclipse.text/src/org/eclipse/text/undo/DocumentUndoManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2016 IBM Corporation and others.
+ * Copyright (c) 2006, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Paul Pazderski - Bug 549755: use {@link DocumentRewriteSession} if operation has lot of changes
*******************************************************************************/
package org.eclipse.text.undo;
@@ -36,6 +37,8 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.DocumentRewriteSession;
+import org.eclipse.jface.text.DocumentRewriteSessionType;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension4;
import org.eclipse.jface.text.IDocumentListener;
@@ -458,10 +461,21 @@ public class DocumentUndoManager implements IDocumentUndoManager {
c= fChanges.get(0);
fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo, DocumentUndoEvent.ABOUT_TO_UNDO, size > 1);
+ DocumentRewriteSession rewriteSession= null;
+ if (size > 25 && fDocumentUndoManager.fDocument instanceof IDocumentExtension4
+ && ((IDocumentExtension4) fDocumentUndoManager.fDocument).getActiveRewriteSession() == null) {
+ DocumentRewriteSessionType sessionType= size > 1000 ? DocumentRewriteSessionType.UNRESTRICTED : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
+ rewriteSession= ((IDocumentExtension4) fDocumentUndoManager.fDocument).startRewriteSession(sessionType);
+ }
+
for (int i= size - 1; i >= 0; --i) {
c= fChanges.get(i);
c.undoTextChange();
}
+
+ if (rewriteSession != null) {
+ ((IDocumentExtension4) fDocumentUndoManager.fDocument).stopRewriteSession(rewriteSession);
+ }
fDocumentUndoManager.resetProcessChangeState();
fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fPreservedText, c.fText, uiInfo,
DocumentUndoEvent.UNDONE, size > 1);
@@ -479,10 +493,21 @@ public class DocumentUndoManager implements IDocumentUndoManager {
c= fChanges.get(size - 1);
fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.ABOUT_TO_REDO, size > 1);
- for (int i= 0; i <= size - 1; ++i) {
+ DocumentRewriteSession rewriteSession= null;
+ if (size > 25 && fDocumentUndoManager.fDocument instanceof IDocumentExtension4
+ && ((IDocumentExtension4) fDocumentUndoManager.fDocument).getActiveRewriteSession() == null) {
+ DocumentRewriteSessionType sessionType= size > 1000 ? DocumentRewriteSessionType.UNRESTRICTED : DocumentRewriteSessionType.UNRESTRICTED_SMALL;
+ rewriteSession= ((IDocumentExtension4) fDocumentUndoManager.fDocument).startRewriteSession(sessionType);
+ }
+
+ for (int i= 0; i < size; ++i) {
c= fChanges.get(i);
c.redoTextChange();
}
+
+ if (rewriteSession != null) {
+ ((IDocumentExtension4) fDocumentUndoManager.fDocument).stopRewriteSession(rewriteSession);
+ }
fDocumentUndoManager.resetProcessChangeState();
fDocumentUndoManager.fireDocumentUndo(c.fStart, c.fText, c.fPreservedText, uiInfo, DocumentUndoEvent.REDONE, size > 1);
}

Back to the top