Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IReusableEditor;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
Expand Down Expand Up @@ -937,10 +938,9 @@ private static UnifiedDiffCandidate unifiedDiffCandidateOf(CompareEditorInput in
ITypedElement right = compareInput.getRight();
IEditorInput leftEditorInput = documentKeyOf(left);
IEditorInput rightEditorInput = documentKeyOf(right);
// The side shown in the editor is preferably a workspace file; an editor opened
// on anything else, a revision for example, comes up empty. The other side
// merely supplies the diff source and may be missing entirely, as for a newly
// added file.
// The side shown in the editor is preferably a workspace file, so that the
// overlay stays editable. The other side merely supplies the diff source and
// may be missing entirely, as for a newly added file.
if (leftEditorInput instanceof IFileEditorInput) {
return new UnifiedDiffCandidate(compareInput, leftEditorInput, left, UnifiedDiffMode.REVERT_MODE, right);
}
Expand All @@ -950,8 +950,6 @@ private static UnifiedDiffCandidate unifiedDiffCandidateOf(CompareEditorInput in
}
// A deleted file leaves no workspace file to overlay. The version that still
// exists is then shown read-only, with its whole content marked as removed.
// Two sides that both exist are left to the classic compare editor, because
// neither of them is the state on disk.
if (rightEditorInput != null && isAbsent(left)) {
return new UnifiedDiffCandidate(compareInput, rightEditorInput, right,
UnifiedDiffMode.OVERLAY_READ_ONLY_MODE, left);
Expand All @@ -960,6 +958,12 @@ private static UnifiedDiffCandidate unifiedDiffCandidateOf(CompareEditorInput in
return new UnifiedDiffCandidate(compareInput, leftEditorInput, left,
UnifiedDiffMode.OVERLAY_READ_ONLY_MODE, right);
}
// Revision history entries use storage editor inputs. Show the right-hand
// revision in a read-only editor and overlay the left-hand revision onto it.
if (leftEditorInput instanceof IStorageEditorInput && rightEditorInput instanceof IStorageEditorInput) {
return new UnifiedDiffCandidate(compareInput, rightEditorInput, right,
UnifiedDiffMode.OVERLAY_READ_ONLY_MODE, left);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,16 +467,17 @@ public void testUnifiedEditorOpensOnTheRevisionWhenTheWorkspaceFileIsDeleted() t
"the unified diff must be shown on the version that still exists"); //$NON-NLS-1$
}

/**
* Two versions that both carry content, staged changes for example, keep opening
* the classic compare editor: neither of them is the state on disk.
*/
/** Two history entries are compared in a read-only unified diff. */
@Test
public void testClassicEditorOpensForTwoRevisions() {
openInput(new RevisionElement("staged.txt", "alpha\nbravo\n"), //$NON-NLS-1$ //$NON-NLS-2$
new RevisionElement("staged.txt", "alpha\nBRAVO\n")); //$NON-NLS-1$ //$NON-NLS-2$
public void testUnifiedEditorOpensForTwoRevisions() {
RevisionElement left = new RevisionElement("staged.txt", "alpha\nbravo\n"); //$NON-NLS-1$ //$NON-NLS-2$
RevisionElement right = new RevisionElement("staged.txt", "alpha\nBRAVO\n"); //$NON-NLS-1$ //$NON-NLS-2$

pumpUntil(UnifiedDiffOpenTest::hasCompareEditor, "the classic compare editor did not take over"); //$NON-NLS-1$
openInput(left, right);

ITextEditor textEditor = assertUnifiedDiffEditor();
assertSame(right.documentKey, textEditor.getEditorInput(),
"the unified diff must be shown on the right-hand revision"); //$NON-NLS-1$
}

/**
Expand Down
Loading