Skip to content

Introduce Unified Diff display mode to Compare editor#2560

Draft
tobiasmelcher wants to merge 1 commit intoeclipse-platform:masterfrom
tobiasmelcher:unified_diff
Draft

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

Conversation

@tobiasmelcher
Copy link
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
Copy link
Contributor

Test Results

0 files   -     54  0 suites   - 54   0s ⏱️ - 34m 49s
0 tests  -  4 546  0 ✅  -  4 523  0 💤  -  23  0 ❌ ±0 
0 runs   - 12 234  0 ✅  - 12 075  0 💤  - 159  0 ❌ ±0 

Results for commit 2f247d4. ± Comparison against base commit fce9709.

@tobiasmelcher
Copy link
Contributor Author

unified_diff

@vogella
Copy link
Contributor

vogella commented Mar 11, 2026

Looks amazing

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.

3 participants