brain: Fix binary file navigation
b872f27da750a1cba9d1bf21608aeda7b368f953
Advance focus before hiding an accepted file and restore its first hunk when acceptance is removed. This keeps binary files selectable while preserving one-step hunk navigation across acceptance toggles. Assisted-by: Codex:gpt-5.6
1 parent
7b8caf1f
crates/brain/src/session.rs
+7 -0
| 826 | 826 | } |
|
| 827 | 827 | ||
| 828 | 828 | /// Persists acceptance or rejection of every hunk in the focused file. |
|
| 829 | 829 | fn toggle_focused_file(&mut self, area: Rect) -> Result<(), Error> { |
|
| 830 | 830 | let current = self.current; |
|
| 831 | + | let pending_only = matches!(self.hunk_visibility, HunkVisibility::Pending); |
|
| 831 | 832 | let before = self.current()?.viewer.state().clone(); |
|
| 832 | 833 | let loaded = self.current()?; |
|
| 833 | 834 | let Some(file) = loaded.viewer.focused_file() else { |
|
| 834 | 835 | loaded.viewer.apply(DiffAction::NextHunk, area); |
|
| 835 | 836 | return Ok(()); |
| 842 | 843 | else { |
|
| 843 | 844 | return Ok(()); |
|
| 844 | 845 | }; |
|
| 845 | 846 | let hunk_ids = file.hunks.iter().map(|hunk| hunk.id).collect::<Vec<_>>(); |
|
| 846 | 847 | let accepted = loaded.review.accepts_all(hunk_ids.iter().copied()); |
|
| 848 | + | if !accepted && pending_only { |
|
| 849 | + | loaded.viewer.apply(DiffAction::FocusNext, area); |
|
| 850 | + | } |
|
| 847 | 851 | let hunks = hunk_ids |
|
| 848 | 852 | .into_iter() |
|
| 849 | 853 | .filter(|hunk| loaded.review.is_accepted(*hunk) == accepted) |
|
| 850 | 854 | .filter(|hunk| loaded.identities.contains_key(hunk)) |
|
| 851 | 855 | .map(|hunk| (current, hunk)) |
|
| 852 | 856 | .collect::<BTreeSet<_>>(); |
|
| 853 | 857 | if accepted { |
|
| 854 | 858 | self.reject_hunks(hunks)?; |
|
| 859 | + | if pending_only { |
|
| 860 | + | self.current()?.viewer.apply(DiffAction::NextHunk, area); |
|
| 861 | + | } |
|
| 855 | 862 | } else { |
|
| 856 | 863 | self.accept_hunks(hunks)?; |
|
| 857 | 864 | } |
|
| 858 | 865 | self.record_navigation_rollback(current, before)?; |
|
| 859 | 866 | Ok(()) |
a.rs
+0 -0
crates/diff/src/viewer.rs
+0 -0
a.rs
+0 -0
image.png
+0 -0
image.png
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
crates/diff/tests/golden/sticky_header_before_next_file_64x5.txt
+0 -0
src/a.rs
+0 -0
src/b.rs
+0 -0
README.md
+0 -0
src/app/a.rs
+0 -0
src/lib/b.rs
+0 -0
README.md
+0 -0
a.rs
+0 -0
b.rs
+0 -0
first.rs
+0 -0
second.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
a.rs\n",
+0 -0
new.rs\n",
+0 -0