brain: Navigate files with n and p

8f4aebdcb4c67b7b3e2a99be036ad3a625d16326
Follow the diff viewer key bindings when moving between files.

Assisted-by: Codex:gpt-5.6-sol
Alexis Sellier committed ago 1 parent 72b40ee0
crates/brain/src/session.rs +2 -1
329 329
                self.refresh_visibility()?;
330 330
                Ok(Control::Redraw)
331 331
            }
332 332
            Event::Key(Key::Char('j')) => self.apply(DiffAction::NextHunk, area),
333 333
            Event::Key(Key::Char('k')) => self.apply(DiffAction::PreviousHunk, area),
334 -
            Event::Key(Key::Char('n' | 'p')) => Ok(Control::Continue),
334 +
            Event::Key(Key::Char('n')) => self.apply(DiffAction::FocusNext, area),
335 +
            Event::Key(Key::Char('p')) => self.apply(DiffAction::FocusPrevious, area),
335 336
            Event::Key(Key::Char('c')) => {
336 337
                self.enter_hunk_view(area)?;
337 338
                Ok(Control::Redraw)
338 339
            }
339 340
            Event::Key(Key::Enter) => {
crates/brain/src/session/status.rs +1 -0
77 77
];
78 78
/// Action hints shown in commit diff mode.
79 79
const COMMIT_ACTIONS: &[(&str, &str)] = &[
80 80
    (TAB_KEY, "history"),
81 81
    ("j/k", "hunk"),
82 +
    ("n/p", "file"),
82 83
    ("a", "accept hunk"),
83 84
    ("c", "comment"),
84 85
];
85 86
/// Action hints shown while browsing hunk comments.
86 87
const HUNK_BROWSE_ACTIONS: &[(&str, &str)] = &[
crates/diff/src/viewer.rs +2 -4
410 410
411 411
impl From<&FileDiff> for FileSummary {
412 412
    fn from(file: &FileDiff) -> Self {
413 413
        let stats = file.stats();
414 414
        Self {
415 -
            loc: Some(file.loc()),
415 +
            loc: (file.header.kind != FileKind::Binary).then(|| file.loc()),
416 416
            stats,
417 417
        }
418 418
    }
419 419
}
420 420
1331 1331
            Event::Key(Key::Ctrl('u')) => {
1332 1332
                DiffAction::Scroll(Scroll::Lines(-((area.rows / 2).max(1) as isize)))
1333 1333
            }
1334 1334
            Event::Key(Key::Char('g') | Key::Home) => DiffAction::Scroll(Scroll::Top),
1335 1335
            Event::Key(Key::Char('G') | Key::End) => DiffAction::Scroll(Scroll::Bottom),
1336 -
            Event::Key(Key::Char('n')) => DiffAction::FocusNext,
1337 -
            Event::Key(Key::Char('p')) => DiffAction::FocusPrevious,
1338 1336
            _ => return Control::Continue,
1339 1337
        };
1340 1338
        match self.apply(action, area) {
1341 1339
            ViewChange::Changed => Control::Redraw,
1342 1340
            ViewChange::Unchanged => Control::Continue,
1948 1946
            .and_then(|focus| targets.iter().position(|target| target.focus == focus))
1949 1947
            .or_else(|| {
1950 1948
                if filter != FocusFilter::File {
1951 1949
                    return None;
1952 1950
                }
1953 -
                self.active_file().and_then(|file| {
1951 +
                self.focused_file().and_then(|file| {
1954 1952
                    targets
1955 1953
                        .iter()
1956 1954
                        .position(|target| target.focus == DiffFocus::File(file))
1957 1955
                })
1958 1956
            });
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
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
assets/css/style.css +0 -0
assets/css/style.css +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
a\n\ +0 -0
crates/diff/tests/golden/file_kinds_80x24.txt +1 -1
16 16
╰─────────────────────────────────────────────────────────────────────────────╯🮘
17 17
╭─────────────────────────────────────────────────────────────────────────────╮🮘
18 18
│ ⊙ mode.sh 0 LOC  mode changed                                               │🮘
19 19
╰─────────────────────────────────────────────────────────────────────────────╯🮘
20 20
╭─────────────────────────────────────────────────────────────────────────────╮🮘
21 -
│ ⊙ image.png 0 LOC  binary                                                   │🮘
21 +
│ ⊙ image.png  binary                                                         │🮘
22 22
╰─────────────────────────────────────────────────────────────────────────────╯🮘
23 23
                                                                               🮘
24 24
                                                                               🮘
crates/diff/tests/golden/focused_second_file_64x6.txt +4 -4
1 1
╭─────────────────────────────────────────────────────────────╮🮘
2 2
│ ⊙ b.rs 2 LOC                                          +1 -1 │🮘
3 -
├─────────────────────────────────────────────────────────────┤🮘
4 -
│  1    1       keep                                          │▗
5 -
│  2          - before                                        │▐
6 -
│       2     + after                                         │▝
3 +
├╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴┤🮘
4 +
│  2          - before                                        │🮘
5 +
│       2     + after                                         │▐
6 +
╰─────────────────────────────────────────────────────────────╯▐