diff: Keep final reviewed file selected

044d8040a193ac759840ef2766501827eee5d975
Preserve the active file when visibility filtering removes every
remaining hunk, while retaining predecessor navigation when reviewable
hunks remain.

Assisted-by: Codex:gpt-5.6-sol
Alexis Sellier committed ago 1 parent 369f7d79
crates/brain/src/session.rs +5 -1
574 574
            self.reject_hunks(BTreeSet::from([(current, hunk)]))?;
575 575
        } else {
576 576
            self.accept_hunks(BTreeSet::from([(current, hunk)]))?;
577 577
        }
578 578
        if !accepted && matches!(self.hunk_visibility, HunkVisibility::Pending) {
579 -
            self.current()?.viewer.apply(DiffAction::NextHunk, area);
579 +
            let loaded = self.current()?;
580 +
            let has_pending = loaded.review.accepted().len() < loaded.identities.len();
581 +
            if has_pending {
582 +
                loaded.viewer.apply(DiffAction::NextHunk, area);
583 +
            }
580 584
        }
581 585
        self.record_navigation_rollback(current, before)?;
582 586
583 587
        Ok(())
584 588
    }
a.rs +0 -0
crates/diff/src/viewer.rs +11 -1
942 942
        predecessors: &[HunkId],
943 943
        active: Option<FileId>,
944 944
        area: Rect,
945 945
    ) {
946 946
        if focus.is_some_and(|focus| !self.has_focus(focus)) {
947 -
            self.set_focus(
947 +
            let has_hunks = self
948 +
                .document
949 +
                .files
950 +
                .iter()
951 +
                .any(|file| !file.hunks.is_empty());
952 +
            let fallback = if has_hunks {
948 953
                predecessors
949 954
                    .iter()
950 955
                    .rev()
951 956
                    .copied()
952 957
                    .map(DiffFocus::Hunk)
953 958
                    .find(|focus| self.has_focus(*focus))
959 +
            } else {
960 +
                active.map(DiffFocus::File)
961 +
            };
962 +
            self.set_focus(
963 +
                fallback
954 964
                    .or_else(|| self.document.commit.is_some().then_some(DiffFocus::Commit))
955 965
                    .or_else(|| active.map(DiffFocus::File)),
956 966
            );
957 967
        }
958 968
        let layout = self.layout(area);
a.rs +0 -0
image.png +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