From 59cecf0906433637ef24053cb030290a071c70a4 Mon Sep 17 00:00:00 2001 From: Tobias Melcher Date: Wed, 16 Sep 2026 14:38:02 +0200 Subject: [PATCH] Support unified diff for version history entries --- .../compare/internal/CompareUIPlugin.java | 16 ++++++++++------ .../compare/tests/UnifiedDiffOpenTest.java | 17 +++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java b/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java index cfd64228f1c..ff0ced52e58 100644 --- a/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java +++ b/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java @@ -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; @@ -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); } @@ -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); @@ -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; } diff --git a/team/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/UnifiedDiffOpenTest.java b/team/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/UnifiedDiffOpenTest.java index 5a1869065d1..41fa7c1d494 100644 --- a/team/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/UnifiedDiffOpenTest.java +++ b/team/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/UnifiedDiffOpenTest.java @@ -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$ } /**