Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java')
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java70
1 files changed, 65 insertions, 5 deletions
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 77dd1a511..1c5a06deb 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -427,6 +427,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
private DocumentMerger fMerger;
/** The current diff */
private Diff fCurrentDiff;
+ private Diff fSavedDiff;
// Bug 259362 - Update diffs after undo
private boolean copyOperationInProgress = false;
@@ -2944,7 +2945,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
*/
private void documentChanged(DocumentEvent e, boolean dirty) {
- IDocument doc= e.getDocument();
+ final IDocument doc= e.getDocument();
if (doc == fLeft.getSourceViewer().getDocument()) {
setLeftDirty(dirty);
@@ -2953,8 +2954,64 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
if (!isLeftDirty() && !isRightDirty()) {
fRedoDiff = false;
+ final Diff oldDiff = getLastDiff();
+ new UIJob(CompareMessages.DocumentMerger_0) {
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ if (!getControl().isDisposed()) {
+ doDiff();
+ if (!getControl().isDisposed()) {
+ Diff newDiff = findNewDiff(oldDiff);
+ if (newDiff != null) {
+ updateStatus(newDiff);
+ setCurrentDiff(newDiff, true);
+ }
+ invalidateLines();
+ updateLines(doc);
+ }
+ }
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ } else {
+ updateLines(doc);
+ }
+ }
+
+
+ private void saveDiff() {
+ fSavedDiff = fCurrentDiff;
+ }
+
+ private Diff getLastDiff() {
+ if (fCurrentDiff != null) {
+ return fCurrentDiff;
}
- updateLines(doc);
+ return fSavedDiff;
+ }
+
+
+ private Diff findNewDiff(Diff oldDiff) {
+ if (oldDiff == null)
+ return null;
+ Diff newDiff = findNewDiff(oldDiff, LEFT_CONTRIBUTOR);
+ if (newDiff == null) {
+ newDiff = findNewDiff(oldDiff, RIGHT_CONTRIBUTOR);
+ }
+ return newDiff;
+ }
+
+ private Diff findNewDiff(Diff oldDiff, char type) {
+ int offset = oldDiff.getPosition(type).offset;
+ int length = oldDiff.getPosition(type).length;
+
+ // DocumentMerger.findDiff method doesn't really work well with 0-length
+ // diffs
+ if (length == 0) {
+ if (offset > 0)
+ offset--;
+ length = 1;
+ }
+ return fMerger.findDiff(type, offset, offset + length);
}
/*
@@ -3269,7 +3326,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
fAncestor.resetLineBackground();
fLeft.resetLineBackground();
fRight.resetLineBackground();
-
+ saveDiff();
fCurrentDiff= null;
try {
fMerger.doDiff();
@@ -4427,9 +4484,11 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
// now switch diffs
+ saveDiff();
fCurrentDiff= d;
revealDiff(d, d.isToken());
} else {
+ saveDiff();
fCurrentDiff= d;
}
@@ -4680,7 +4739,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
*/
private boolean copy(Diff diff, boolean leftToRight) {
- if (diff != null && !diff.isResolved()) {
+ if (diff != null) {
if (!validateChange(!leftToRight))
return false;
if (leftToRight) {
@@ -5008,6 +5067,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
private void resetDiffs() {
// clear stuff
+ saveDiff();
fCurrentDiff= null;
fMerger.reset();
resetPositions(fLeft.getSourceViewer().getDocument());

Back to the top