Skip to content

Introduce Unified Diff display mode to Compare editor#2560

Open
tobiasmelcher wants to merge 1 commit into
eclipse-platform:masterfrom
tobiasmelcher:unified_diff
Open

Introduce Unified Diff display mode to Compare editor#2560
tobiasmelcher wants to merge 1 commit into
eclipse-platform:masterfrom
tobiasmelcher:unified_diff

Conversation

@tobiasmelcher

Copy link
Copy Markdown
Contributor

Add Unified Diff Display in Text Editor as Alternative to Classic 2-Way Compare

Implements eclipse-platform/eclipse.platform.ui#3771

Summary

This contribution introduces a new Unified Diff viewing mode for org.eclipse.compare that displays differences in a single editor pane, similar to git diff or GitHub's pull request view. When enabled, it replaces the traditional side-by-side 2-way compare editor for read-only comparisons, providing a more compact and familiar diff experience.

This is a draft implementation to gather early feedback from the Eclipse community on:

  • API design and public interface shape
  • Integration approach with existing compare infrastructure
  • User experience and workflow expectations
  • Performance and edge case handling

What's Included

1. New Public API (org.eclipse.compare.unifieddiff)

Added a new public package with the UnifiedDiff class as the main entry point for programmatically opening unified diffs in text editors.

Supported Modes:

  • REPLACE_MODE: Diffs are directly applied to the editor content. Users can keep or undo individual changes.
  • OVERLAY_MODE: Source content remains unmodified. Diffs are shown via code mining annotations, and users can selectively apply or cancel individual changes.
  • OVERLAY_READ_ONLY_MODE: Source content remains unmodified and read-only. Diffs are shown via code mining annotations for viewing only.

API Example:

UnifiedDiff.create(editor, sourceContent, UnifiedDiffMode.OVERLAY_READ_ONLY_MODE)
    .ignoreWhiteSpace(true)
    .open();

2. Preference Page Integration

Added a new checkbox in Preferences > General > Compare/Patch:

  • "Use Unified Diff instead of 2-way compare when possible"

When enabled, eligible compare operations automatically use the unified diff viewer instead of the traditional side-by-side editor.

3. Automatic Compare Editor Integration

Modified CompareUIPlugin#openCompareEditor() to detect when unified diff should be used:

  • Only applies to 2-way comparisons (left vs. right, no ancestor)
  • Only applies to read-only comparisons (no editing capabilities needed)
  • Automatically extracts content and opens in unified diff mode when preference is enabled

How to Test

Prerequisites

  • Eclipse workspace with a Java project tracked in a Git repository

Steps

  1. Open Window > Preferences > General > Compare/Patch
  2. Enable the checkbox: "Use Unified Diff instead of 2-way compare when possible"
  3. In the Package Explorer, right-click a Java file
  4. Select Team > Show in History
  5. In the History view, select two different commits
  6. Right-click and choose Compare with Each Other

Expected Result:

  • Instead of the traditional side-by-side compare editor, a single editor opens showing the unified diff
  • Added lines appear with green background highlighting
  • Deleted lines appear as code mining annotations with red background
  • Character-level changes within modified lines are highlighted with darker shades

Next Steps

  • Remove reflection calls - Enhance the code mining APIs so that the current reflection calls can be removed
  • Code cleanup - Polish implementation
  • Bug fixes - Address issues reported by the Eclipse community
  • UI/UX improvements - Enhance user experience based on the community feedback

@github-actions

github-actions Bot commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Test Results

    54 files  ±0      54 suites  ±0   36m 18s ⏱️ -12s
 4 671 tests ±0   4 649 ✅ ±0   22 💤 ±0  0 ❌ ±0 
11 907 runs  ±0  11 754 ✅ ±0  153 💤 ±0  0 ❌ ±0 

Results for commit 2221516. ± Comparison against base commit 6960419.

♻️ This comment has been updated with latest results.

@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

unified_diff

@vogella

vogella commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Looks amazing

@HeikoKlare

Copy link
Copy Markdown
Contributor

I very much like that feature. I would be in favor of integrating a usable state as early as possible and incrementally improve it, so that it becomes easy to test and so that you get feedback soon.

You currently seem to introduce new API with the org.eclipse.compare.unifieddiff package. Is it necessary to export that package at all or can it stay internal (for now)? If the feature can be added as configurable opt-in/opt-out without adding any new API, it could even be integrated in a rather experimental state, as it can be disabled and also incrementally improved or, in case of problems, even removed again without having to consider any effects on existing consumers.

@vogella

vogella commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

@tobias-melcher can you finish this one? Would be awesome to have this as option (hopefully the default 1-2 releases later).

@laeubi

laeubi commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

that displays differences in a single editor pane, similar to git diff or GitHub's pull request view.

For me github shows by default a split view (what often is a bit better than the eclipse one but that's a different story) and one has to explicitly select "unified" - so I don't think one is the "default" over the other but its just two options one can switch between and depends on preference of the user.

@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

@tobias-melcher can you finish this one? Would be awesome to have this as option (hopefully the default 1-2 releases later).

Sure, I will do my best. I think the most important topic is that we get rid of the reflection calls. I will concentrate on this topic in the next weeks. I understand the request to make this feature available as early as possible and mark it as experimental. I will do this.

tobiasmelcher pushed a commit to tobiasmelcher/eclipse.platform.ui that referenced this pull request Apr 6, 2026
list

Adds a new public API method `getMinings()` to
`AbstractInlinedAnnotation` that provides read-only access to the list
of `ICodeMining` instances associated with an inlined annotation.

This API is needed to implement the unified diff feature via
eclipse-platform/eclipse.platform#2560
@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

I very much like that feature. I would be in favor of integrating a usable state as early as possible and incrementally improve it, so that it becomes easy to test and so that you get feedback soon.

You currently seem to introduce new API with the org.eclipse.compare.unifieddiff package. Is it necessary to export that package at all or can it stay internal (for now)? If the feature can be added as configurable opt-in/opt-out without adding any new API, it could even be integrated in a rather experimental state, as it can be disabled and also incrementally improved or, in case of problems, even removed again without having to consider any effects on existing consumers.

@HeikoKlare I marked the package as "provisional API" and added "EXPERIMENTAL" to the preference label with [900a124]. Would you prefer to add "internal" to package "org.eclipse.compare.unifieddiff" or is x-internal sufficient?

tobiasmelcher pushed a commit to tobiasmelcher/eclipse.platform.ui that referenced this pull request Apr 6, 2026
list

Adds a new public API method `getMinings()` to
`AbstractInlinedAnnotation` that provides read-only access to the list
of `ICodeMining` instances associated with an inlined annotation.

This API is needed to implement the unified diff feature via
eclipse-platform/eclipse.platform#2560
private UnifiedDiff() {
}

public static enum UnifiedDiffMode {

@danthe1st danthe1st Apr 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is API, I think using an enum here means that adding enum constants is a backwards incompatible change? Should this be updated to allow for adding new values without breaking compatibility?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot for the feedback @danthe1st . I have replaced the enum with a type-safe constant class [af1f8ef]. Do you have any further feedback?
I’d also like to better understand the compatibility concern: is adding an additional enum value really considered binary incompatible? If so, could you please point me to the relevant documentation that explains why enums are not allowed in Eclipse APIs?

@danthe1st danthe1st Apr 7, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about that being anywhere in the Eclipse documentation but imagine this enum:

enum MyEnum {
    A, B
}

We can then use exhaustive switch expressions:

int oneBasedIndex(MyEnum e){
    return switch(e) {
         case A -> 1;
         case B -> 2;
         // case null -> 0; // optional
    };
}

Adding a new enum constant C will result in:

  • A compilation failure at the index method
    method
  • An Error at runtime when oneBasedIndex is called with MyEnum.C without recompiling/replacing the compilation unit containing MyEnum.C

I think there's also a way to reproduce this in JDKs before switch expressions using definite assignment rules (ensuring a variable is initialized).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the clarification. Makes sense to me. You convinced me not to use enums in APIs.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, https://github.com/eclipse-platform/eclipse.platform/blob/master/docs/Evolving-Java-based-APIs-2.md#evolving-api-classes mentions

Add enum constant - Binary compatible (8)

and

(8) Client code can use the values() method to determine the ordinal positions of the enum constants. So although this is a binary compatible change, it may break contractual compatibility.

But I guess there's an argument to be made against that for the reasons I mentioned above.

tobiasmelcher pushed a commit to tobiasmelcher/eclipse.platform.ui that referenced this pull request Apr 7, 2026
list

Adds a new public API method `getMinings()` to
`AbstractInlinedAnnotation` that provides read-only access to the list
of `ICodeMining` instances associated with an inlined annotation.

This API is needed to implement the unified diff feature via
eclipse-platform/eclipse.platform#2560
tobiasmelcher pushed a commit to eclipse-platform/eclipse.platform.ui that referenced this pull request Apr 8, 2026
list

Adds a new public API method `getMinings()` to
`AbstractInlinedAnnotation` that provides read-only access to the list
of `ICodeMining` instances associated with an inlined annotation.

This API is needed to implement the unified diff feature via
eclipse-platform/eclipse.platform#2560
@HeikoKlare

Copy link
Copy Markdown
Contributor

I marked the package as "provisional API" and added "EXPERIMENTAL" to the preference label with [https://github.com/eclipse-platform/eclipse.platform/commit/900a1249ad58a3086b2f2bd116ec918adfea2849]. Would you prefer to add "internal" to package "org.eclipse.compare.unifieddiff" or is x-internal sufficient?

I think marking the package as x-internal is sufficient. It's just important that OSGi will by default not allow you to access any content of that package. If I am not mistaken, we also have other packages that are marked into without having "internal" in their name (though it probably used to be common practice to have internal packages named like that some time ago).

@vogella

vogella commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

The old conversation was: use internal in package name if you do not plan to release it as API . Use x-internal if you plan to release it as API at some point in time but you are not yet ready for that

@vogella

vogella commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

@tobiasmelcher can I help with moving this forward?

@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

@tobiasmelcher can I help with moving this forward?

@vogella thanks a lot for asking and for offering to help. Sorry for the slow progress on my side. I haven’t had as much time as I expected over the last few weeks, so I wasn’t able to move this forward properly. I really appreciate your patience and support.
Could you please help me with a review of eclipse-platform/eclipse.platform.ui#3868? Do you think I should add a unit test to 3868 to better document the intended behavior?
PR #3868 is required so that this unified diff pull request will build properly. I’m aware that the current state is still quite early and that there’s a lot more work to do. However, this would allow us to merge an initial version and then continue working on the unified diff feature in parallel.

@vogella

vogella commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

@tobiasmelcher can I help with moving this forward?

@vogella thanks a lot for asking and for offering to help. Sorry for the slow progress on my side. I haven’t had as much time as I expected over the last few weeks, so I wasn’t able to move this forward properly. I really appreciate your patience and support. Could you please help me with a review of eclipse-platform/eclipse.platform.ui#3868? Do you think I should add a unit test to 3868 to better document the intended behavior? PR #3868 is required so that this unified diff pull request will build properly. I’m aware that the current state is still quite early and that there’s a lot more work to do. However, this would allow us to merge an initial version and then continue working on the unified diff feature in parallel.

Just as a remark, as Eclipse committer you can ask for a free pro Copilot license in your user profile, afterwards the Copilot CLI allows you to use Claude Opus 4.7 (or 4.6 in case the roll-out of 4.7 has not yet reached you) via the /model setting. Highly recommended in case you need assistance.

@vogella

vogella commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Could you please help me with a review of eclipse-platform/eclipse.platform.ui#3868?

Review is posted

@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

Could you please help me with a review of eclipse-platform/eclipse.platform.ui#3868?

Review is posted

Thanks a lot.

@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

Hi @vogella ,
could you please help me in setting the dark theme colors for the new marker annotations defined in the plugin.xml: org.eclipse.compare.unifieddiff.internal.addition
org.eclipse.compare.unifieddiff.internal.deletion
org.eclipse.compare.unifieddiff.internal.detailedAddition
org.eclipse.compare.unifieddiff.internal.detailedDeletion

I added a dark.css file and registered it in the plugin.xml:

<extension point="org.eclipse.e4.ui.css.swt.theme">
  <stylesheet uri="resources/css/dark.css">
     <themeid refid="org.eclipse.e4.ui.css.theme.e4_dark"></themeid>
  </stylesheet>
</extension>

The content in the dark.css seems not to be correct:

IEclipsePreferences#org-eclipse-ui-editors:org-eclipse-ui-themes {
	preferences:
		'inlineDiffColor=27,40,30'
		'detailedInlineDiffColor=24,50,27'
		'deletionInlineDiffColor=52,27,30'
		'detailedDeletionInlineDiffColor=74,24,27'
}

Unfortunately, the light colors are used in the dark theme and not the registered ones in dark.css:

light dark

Do you know how to fix this?

Thanks a lot,
Tobias

@vogella

vogella commented May 2, 2026

Copy link
Copy Markdown
Contributor

Looks like the css is not in the build.properties?

@vogella

vogella commented May 3, 2026

Copy link
Copy Markdown
Contributor

This is is incorrect:

IEclipsePreferences#org-eclipse-ui-editors:org-eclipse-ui-themes {

The Pseudo class (:org-eclipse-ui-themes) is supposed to be the plug-in which contributes this, would be the ID of the bundle you have this in (the compare one), otherwise it gets overridden by the exsting org-eclipse-ui-editors:org-eclipse-ui-themes node or overrides it.

I implemented this pseudo functionality to allow multiple plug-ins to contribute preference values for ui-editor preference node.

@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

This is is incorrect:

IEclipsePreferences#org-eclipse-ui-editors:org-eclipse-ui-themes {

The Pseudo class (:org-eclipse-ui-themes) is supposed to be the plug-in which contributes this, would be the ID of the bundle you have this in (the compare one), otherwise it gets overridden by the exsting org-eclipse-ui-editors:org-eclipse-ui-themes node or overrides it.

I implemented this pseudo functionality to allow multiple plug-ins to contribute preference values for ui-editor preference node.

Thanks a lot for the very fast response. Colors for the editor annotations are now taken from dark.css, great.

dark2

@vogella

vogella commented May 3, 2026

Copy link
Copy Markdown
Contributor

Nice. So from your side this change is ready?

@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

Nice. So from your side this change is ready?

I want to implement some unit tests, remove the test commands (TestUnidiffCommand, ...) and run some AI reviews.
There are performance issues with SAPs ABAP Editor which I have not faced with the Java editor (the syntax coloring implementation for ABAP is much more complex and expensive compared to the Java implementation).

Ready is a big word; I would say we have a very first experimental version which could be used by interested users.

When is the next dev close? Can we merge the first version in the beginning of the next release cycle?

@HeikoKlare

Copy link
Copy Markdown
Contributor

When is the next dev close? Can we merge the first version in the beginning of the next release cycle?

For the Eclipse Platform, M3 is next next Friday. RC2 is two weeks later (29th May) and usually the master branch will be opened for development of the next release shortly after. So beginning of June would be a good time for merging this. If I am not mistaken, the current proposal is a completely internal implementation with an opt-in feature, which in my opinion is perfect for merging in a rather early, experimental state and then improving incrementally while already having interested people testing it.

@tobiasmelcher tobiasmelcher force-pushed the unified_diff branch 3 times, most recently from 8d25e19 to 7007282 Compare May 29, 2026 14:54
@tobiasmelcher tobiasmelcher force-pushed the unified_diff branch 2 times, most recently from be20078 to e87f770 Compare June 5, 2026 12:55
@tobiasmelcher tobiasmelcher marked this pull request as ready for review June 5, 2026 13:13
@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

Hi everyone,

I have just rebased this PR onto the latest master, so it is now up to date and ready for review.

Please note that the Unified Diff feature introduced here is an early experimental version. The intention of merging it at this stage is to gather initial feedback from the community so users can try it out, report issues, and help guide its further development.
The feature is opt in via a preference, which means the existing 2 way compare remains the default and is unaffected.
I would really appreciate it if you could take a look and share your feedback or concerns. In particular, are there any objections to merging this initial experimental version?
If there are no objections, I plan to proceed with merging next week.

Thanks a lot,
Tobias

@HeikoKlare HeikoKlare left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for merging this to allow easy testing of the new diff UI. Since the feature is marked experimental in the UI and technically internal, I do not see any risk in integrating it as is.
Note that I did not do a review of the code, but just found a typo by accident when look for how the feature is presented in the UI, which is why I have a single review comment.

Thank you again for working on this, @tobiasmelcher! Looking forward to having this available in the IDE and testing it.

public static final String ADDED_LINES_REGEX= PREFIX + "AddedLinesRegex"; //$NON-NLS-1$
public static final String REMOVED_LINES_REGEX= PREFIX + "RemovedLinesRegex"; //$NON-NLS-1$
public static final String SWAPPED = PREFIX + "Swapped"; //$NON-NLS-1$
public static final String UNIFIED_DIFF = PREFIX + "UnitifedDiff"; //$NON-NLS-1$

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static final String UNIFIED_DIFF = PREFIX + "UnitifedDiff"; //$NON-NLS-1$
public static final String UNIFIED_DIFF = PREFIX + "UnifiedDiff"; //$NON-NLS-1$

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot Heiko, typo should be fixed with [95145e2]. I can remember that I fixed this typo some time ago, but somehow got lost then.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an experimental “Unified Diff” viewing mode for org.eclipse.compare, integrating a single-pane diff presentation (via annotations + code minings) into the text editor workflow and adding a preference to use it automatically for eligible 2‑way, read-only comparisons.

Changes:

  • Added a new unified diff API surface (org.eclipse.compare.unifieddiff) plus internal implementation for diff computation, annotations, toolbars, and code mining rendering.
  • Integrated unified diff opening into CompareUIPlugin#openCompareEditor() behind a new Compare/Patch preference.
  • Added styling/resources (dark theme preference overrides, toolbar icons) and UI tests to validate annotation production + paint behavior.

Reviewed changes

Copilot reviewed 24 out of 26 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
team/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/UnifiedDiffManagerTest.java Adds UI-level regression tests ensuring unified diff annotations are produced and can paint without logged errors.
team/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamUITests.java Registers the new unified diff UI test in the UI test suite.
team/bundles/org.eclipse.compare/resources/css/dark.css Defines dark-theme preference overrides for unified diff colors.
team/bundles/org.eclipse.compare/plugin.xml Registers code mining provider + annotation types/specifications and dark-theme stylesheet.
team/bundles/org.eclipse.compare/plugin.properties Adds label text for the new “Unified Diff” preference.
team/bundles/org.eclipse.compare/META-INF/MANIFEST.MF Exports the new unified diff package (currently marked internal).
team/bundles/org.eclipse.compare/icons/full/elcl16/undo.svg Adds toolbar icon for revert/undo-all behavior in unified diff.
team/bundles/org.eclipse.compare/icons/full/elcl16/remove_highlighting.svg Adds toolbar icon for hiding diffs.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/UnifiedDiffMode.java Introduces unified diff display mode constants.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/UnifiedDiff.java Adds the public entry point/builder for opening unified diffs in editors.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/UnifiedDiffManager.java Core unified diff engine: computes diffs, manages annotations, listeners, toolbars, and repaint coordination.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/UnifiedDiffCodeMiningProvider.java Renders unified diff deletions/additions via line header/footer code minings and token-level highlighting.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/UndoAllRunnable.java Implements “Undo All” action for replace-mode flows.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/PreviousRunnable.java Implements previous-diff navigation action.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/NextRunnable.java Implements next-diff navigation action.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/KeepAllRunnable.java Implements “Keep All” for replace-mode flows.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/HideAllDiffsRunnable.java Implements “Hide All Diffs” action and unified diff cleanup.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/AcceptAllRunnable.java Implements “Accept/Revert All” action and applies changes into the document.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/merge/DocumentMerger.java Exposes merger input to support unified diff token/whitespace contributors.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ICompareUIConstants.java Adds icon constant for the “open 2‑way compare” action.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java Adds unified diff preference handling and automatic unified diff opening in compare editor workflow.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java Adds preference key/default and UI checkbox for unified diff mode.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties Adds unified diff toolbar/action strings and error text.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java Exposes the new message keys as fields.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java Adds adapter for IDocumentMergerInput and makes dispose path more null-safe.
team/bundles/org.eclipse.compare/build.properties Ensures the new resources/ directory is included in the build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +691 to +695
} catch (CoreException | IOException e) {
CompareUIPlugin.log(e);
}
return null;
}
Comment on lines +768 to +772
var invisibleParent = new Shell();
try {
invisibleParent.setVisible(false);
var viewer = input.findContentViewer(new NullViewer(getShell()), compareInput, invisibleParent);
if (viewer instanceof IAdaptable adaptable) {
Comment on lines +600 to +605
try {
IWorkbenchPage wpage = page != null ? page : getActivePage();
if (unifiedDiffInput.left instanceof IFileEditorInput) {
IEditorPart leftEditor = wpage.openEditor(unifiedDiffInput.left,
getEditorId(unifiedDiffInput.left, unifiedDiffInput.leftElement));
if (leftEditor instanceof MultiPageEditorPart mpe) {
Comment on lines 66 to +68
org.eclipse.ui.services,
org.eclipse.ui.texteditor"
org.eclipse.ui.texteditor",
org.eclipse.compare.unifieddiff;x-internal:=true
Comment on lines +461 to +472
<extension point="org.eclipse.ui.editors.annotationTypes">
<type
name="org.eclipse.compare.unifieddiff.internal.addition"
markerType="org.eclipse.core.resources.problemmarker"
markerSeverity="0">
</type>
<type
name="org.eclipse.compare.unifieddiff.internal.deletion"
markerType="org.eclipse.core.resources.problemmarker"
markerSeverity="0">
</type>
</extension>
Comment on lines +235 to +239
// call validateEdit before modifying the leftDocument
IFile file = editor.getEditorInput().getAdapter(IFile.class);
if (file != null && !validateEdit(file)) {
return Status.CANCEL_STATUS;
}
Comment on lines +1210 to +1218
RGB color;
if (mode.equals(UnifiedDiffMode.OVERLAY_MODE) || mode.equals(UnifiedDiffMode.OVERLAY_READ_ONLY_MODE)) {
color = JFaceResources.getColorRegistry().getRGB("DELETION_COLOR"); //$NON-NLS-1$
} else {
color = JFaceResources.getColorRegistry().getRGB("ADDITION_COLOR"); //$NON-NLS-1$
}
RGB background = UnifiedDiffCodeMiningProvider.getBackground();
RGB interpolated = UnifiedDiffCodeMiningProvider.interpolate(color, background, 0.9);
this.additionBackgroundColor = new Color(interpolated);
Comment on lines +139 to +144
int tabWidth = getTabWidth(viewer);
return CompletableFuture.supplyAsync(() -> {
List<ICodeMining> minings = new ArrayList<>();
createLineHeaderCodeMinings(diffs, minings, viewer, tabWidth);
return minings;
});
Comment on lines +89 to +102
if (Display.getCurrent() != null && (this.deletionBackgroundColor == null || isOverlay != lastIsOverlay)) {
// check class ColorPalette
RGB background = getBackground();
String colorName;
if (isOverlay) {
colorName = "ADDITION_COLOR"; //$NON-NLS-1$
} else {
colorName = "DELETION_COLOR"; //$NON-NLS-1$
}
RGB deletionColor = JFaceResources.getColorRegistry().getRGB(colorName);
this.detailedDiffColor = new Color(interpolate(deletionColor, background, 0.9));
this.deletionBackgroundColor = new Color(interpolate(deletionColor, background, 0.8));
lastIsOverlay = isOverlay;
}
Compare

This contribution introduces a new Unified Diff viewing mode for
org.eclipse.compare that displays differences in a single editor pane,
similar to git diff or GitHub's pull request view. When enabled, it
replaces the traditional side-by-side 2-way compare editor for read-only
comparisons, providing a more compact and familiar diff experience.
@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

Copilot findings fixed with [2221516]

@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

I just discovered a "Show Unified Diff" context menu entry in the Git History view.

image image

How does this existing functionality relate to the feature proposed in this pull request? The unified diff in this PR is rendered inside the text editor using code minings and text editor annotations, whereas the existing feature opens the unified diff in a separate editor.

What do you think? Can both features coexist?

@iloveeclipse

Copy link
Copy Markdown
Member

What do you think? Can both features coexist?

They has to. Egit releases support older Eclipse platforms.

@tomaswolf

Copy link
Copy Markdown
Member

Can both features coexist?

Of course they can; this is not a CompareEditor. EGit also shows a diff, not a single file comparison, with hunk headers.

It would be nice if the new feature used the same colors as the EGit feature. EGit defines the dark mode colors at https://github.com/eclipse-egit/egit/blob/master/org.eclipse.egit.ui/css/e4-dark_egit_prefstyle.css , the default values (used in light mode) are at https://github.com/eclipse-egit/egit/blob/6f540c80c3b992787e6f7cb67d92d586385b6985/org.eclipse.egit.ui/plugin.xml#L880 and following.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants