From f3b8308c832b099e7b9a034ecc117bffe054cfb9 Mon Sep 17 00:00:00 2001 From: Ayush <63203492+macayu17@users.noreply.github.com> Date: Mon, 17 Aug 2026 18:16:10 +0000 Subject: [PATCH] git_ui: Enable navigation for single-hunk diffs (#62615) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What Keep the hunk navigation controls available when a diff contains one hunk, so users can return to it after scrolling away. This applies to solo, staged, unstaged, and project diff views. ## Why The controls were only rendered when `hunk_count > 1`, even though the existing navigation actions already wrap and recenter a single hunk. ## How Render the previous and next hunk controls whenever `hunk_count > 0`, reusing the existing navigation actions. Closes #62469 ## Testing - `cargo +stable-x86_64-pc-windows-gnu test -p git_ui --lib` — 130 passed. - `cargo +stable-x86_64-pc-windows-gnu build -p zed -j 1` — passed. - `rustfmt --edition 2024 --check` on the four changed files — passed. - `git diff --check` — passed. - Manually verified with the branch-built Zed on Windows: opened a tracked file with exactly one diff hunk, expanded the context, scrolled below the hunk, and used **Go to Previous Hunk**. The view returned to the changed line. ## Showcase https://github.com/user-attachments/assets/e7b63030-50ad-4536-8266-13987ed85f3d ## Self-Review Checklist - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://zed.dev/docs/development/ux-ui) and [icon guidelines](https://zed.dev/docs/development/ui-icons)) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Enable "Go to Previous Hunk" and "Go to Next Hunk" buttons even if there's a single diff hunk. --- crates/git_ui/src/project_diff.rs | 2 +- crates/git_ui/src/solo_diff_view.rs | 2 +- crates/git_ui/src/staged_diff.rs | 2 +- crates/git_ui/src/unstaged_diff.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/git_ui/src/project_diff.rs b/crates/git_ui/src/project_diff.rs index 55fb5f40fa..4fa62a513d 100644 --- a/crates/git_ui/src/project_diff.rs +++ b/crates/git_ui/src/project_diff.rs @@ -323,7 +323,7 @@ impl ProjectDiff { let editor = diff.editor().read(cx).rhs_editor().clone(); let editor = editor.read(cx); let snapshot = diff.multibuffer().read(cx).snapshot(cx); - let prev_next = snapshot.diff_hunks().nth(1).is_some(); + let prev_next = snapshot.diff_hunks().next().is_some(); let (selection, ranges) = diff.selected_ranges(cx); let mut has_staged_hunks = false; let mut has_unstaged_hunks = false; diff --git a/crates/git_ui/src/solo_diff_view.rs b/crates/git_ui/src/solo_diff_view.rs index 0ccb2183ba..904ef06936 100644 --- a/crates/git_ui/src/solo_diff_view.rs +++ b/crates/git_ui/src/solo_diff_view.rs @@ -269,7 +269,7 @@ impl SoloDiffView { let editor = self.editor.read(cx).rhs_editor().read(cx); let multibuffer = editor.buffer().read(cx); let snapshot = multibuffer.snapshot(cx); - let prev_next = snapshot.diff_hunks().nth(1).is_some(); + let prev_next = snapshot.diff_hunks().next().is_some(); let mut selection = true; let mut ranges = editor diff --git a/crates/git_ui/src/staged_diff.rs b/crates/git_ui/src/staged_diff.rs index 648b1980eb..60cd0942a6 100644 --- a/crates/git_ui/src/staged_diff.rs +++ b/crates/git_ui/src/staged_diff.rs @@ -268,7 +268,7 @@ impl StagedDiff { let editor = diff.editor().read(cx).rhs_editor().clone(); let editor = editor.read(cx); let snapshot = diff.multibuffer().read(cx).snapshot(cx); - let prev_next = snapshot.diff_hunks().nth(1).is_some(); + let prev_next = snapshot.diff_hunks().next().is_some(); let (selection, ranges) = diff.selected_ranges(cx); let unstage = editor .diff_hunks_in_ranges(&ranges, &snapshot) diff --git a/crates/git_ui/src/unstaged_diff.rs b/crates/git_ui/src/unstaged_diff.rs index e4a5165bb8..3e677353cf 100644 --- a/crates/git_ui/src/unstaged_diff.rs +++ b/crates/git_ui/src/unstaged_diff.rs @@ -322,7 +322,7 @@ impl UnstagedDiff { let editor = diff.editor().read(cx).rhs_editor().clone(); let editor = editor.read(cx); let snapshot = diff.multibuffer().read(cx).snapshot(cx); - let prev_next = snapshot.diff_hunks().nth(1).is_some(); + let prev_next = snapshot.diff_hunks().next().is_some(); let (selection, ranges) = diff.selected_ranges(cx); let stage = editor .diff_hunks_in_ranges(&ranges, &snapshot)