From 920ab8ec71df0f6ec967a047e06e2670847cd164 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Fri, 31 Jul 2026 12:26:22 +0200 Subject: [PATCH] Keep the unified diff on the side that is a workspace file The unified diff picks the side it overlays: the left one when that is a workspace file, otherwise the right one. For a file that only lives in the git working tree and not in any imported project, neither side is a workspace file, so an editor was opened on the revision instead. That editor comes up empty, and since no diff can be applied to it the classic compare editor opens on top, leaving an empty editor next to it. Only a workspace file is used now; when neither side is one, the classic compare editor takes over on its own. --- .../eclipse/compare/internal/CompareUIPlugin.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 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 52ef72f1ba1..99a089aa5de 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 @@ -824,14 +824,18 @@ private UnifiedDiffSource prepareUnifiedDiff(CompareEditorInput input, IProgress || !(right instanceof IStreamContentAccessor rightSource)) { return null; } - // The side that is not shown in the editor supplies the diff source, so it is - // read here instead of on the UI thread. + // The overlay needs a workspace file to sit on; an editor opened on anything + // else, a revision for example, comes up empty. The other side supplies the + // diff source and is read here rather than on the UI thread. if (leftEditorInput instanceof IFileEditorInput) { return new UnifiedDiffSource(compareInput, leftEditorInput, left, UnifiedDiffMode.REVERT_MODE, getSourceOf(rightSource)); } - return new UnifiedDiffSource(compareInput, rightEditorInput, right, UnifiedDiffMode.OVERLAY_READ_ONLY_MODE, - getSourceOf(leftSource)); + if (rightEditorInput instanceof IFileEditorInput) { + return new UnifiedDiffSource(compareInput, rightEditorInput, right, UnifiedDiffMode.OVERLAY_READ_ONLY_MODE, + getSourceOf(leftSource)); + } + return null; } private static IEditorInput documentKeyOf(ITypedElement element) {