Skip to content

git_ui: Open focused single-file diff from commit diff multibuffer - #62074

Closed
gaojunran wants to merge 2 commits into
zed-industries:mainfrom
gaojunran:solo-diff-view-commit-diff
Closed

git_ui: Open focused single-file diff from commit diff multibuffer#62074
gaojunran wants to merge 2 commits into
zed-industries:mainfrom
gaojunran:solo-diff-view-commit-diff

Conversation

@gaojunran

@gaojunran gaojunran commented Aug 2, 2026

Copy link
Copy Markdown

Summary

When clicking the Open File button or the context menu Open File Diff inside a CommitView's diff multibuffer, the editor currently opens a plain read-only file view with no diff styling. This is confusing — users expect to see a diff, not a bare file.

This PR extends SoloDiffView to support commit diffs, so both entry points open a focused single-file diff view instead.

Showcase

This PR (has diff style):

2026-08-02.19.01.24.mov

Upstream main (no diff style):

2026-08-02.19.07.44.mov

Changes

solo_diff_view.rs

  • Added DiffSource enum (Uncommitted | Commit { sha }) to distinguish working-tree diffs from commit diffs
  • Added open_or_focus_commit() — loads the commit diff, filters to a single file, reuses build_buffer/build_buffer_diff from commit_view.rs, and creates a SoloDiffView with DiffSource::Commit
  • new() accepts a diff_source parameter; commit diffs use RestoreOnlyDiffHunkDelegate (matching CommitView behavior)
  • matches() / matches_commit() — deduplication correctly distinguishes uncommitted and commit diff views
  • button_states() early-returns with all staging/restore buttons disabled for commit diffs
  • SoloDiffGitToolbar — commit diffs only show Prev/Next Hunk + diff stat; staging/commit buttons hidden via .when(!is_commit_diff, ...)
  • SoloDiffStyleToolbar — commit diffs skip the status icon
  • breadcrumbs — commit diffs skip status_for_path (no misleading working-tree status)
  • Tab content shows "{short_sha} — {file_name}"; tooltip shows full SHA + path

commit_view.rs

  • GitBlob, build_buffer, build_buffer_diff changed to pub(crate) for reuse
  • RHS editor sets delegate_open_excerpts(true) — intercepts the "Open File" button click, emits OpenExcerptsRequested
  • handle_editor_event — on OpenExcerptsRequested, extracts the buffer's file path and opens SoloDiffView::open_or_focus_commit
  • clone_on_split — also sets delegate_open_excerpts(true) and subscribes to the event (covers split mode RHS)
  • Context menu entry relabeled to "Open File Diff", calls open_or_focus_commit instead of open_path_preview
  • OpenFileAtHead action handler also calls open_or_focus_commit
  • Extracted open_file_diff helper to eliminate duplicated call pattern
  • Removed open_file_at_head (no longer called)

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Added the ability to open a focused single-file diff view from the commit diff multibuffer, showing diff styling instead of a plain read-only file

When clicking 'Open File' or the context menu 'Open File Diff' inside a
CommitView's diff multibuffer, open a SoloDiffView (focused single-file diff)
instead of a plain read-only file view.

Extends SoloDiffView with a DiffSource enum (Uncommitted | Commit) to support
commit diffs. Commit diff mode uses RestoreOnlyDiffHunkDelegate, hides
staging/commit toolbar buttons, and shows the commit short SHA in the tab title.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Aug 2, 2026
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Aug 2, 2026
@MrSubidubi

Copy link
Copy Markdown
Member

We currently enforce a 3 PR limit per contributor in our
repository contribution guidelines and you are currently way above that limit - since this is a draft, I'll for now close this first. Please wait for feedback and merge first, thank you.

Not saying this cannot be opened again, yet please consider this only if you are within limits again. Thank you.

@MrSubidubi MrSubidubi closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants