feat: toggle diff file review with c in the file picker

This commit is contained in:
Valdemar Lorenzen
2026-10-13 13:17:06 +02:00
parent 38fcf86195
commit 8f87b8d3d1
3 changed files with 45 additions and 2 deletions
+43
View File
@@ -3232,6 +3232,22 @@ impl Editor {
if !self.diff_interacting() && self.handle_selection_binding(&input) {
return None;
}
if files_focused
&& input == Input::Char('c')
&& self
.diff
.as_ref()
.and_then(|diff| diff.files.as_ref())
.is_some_and(|files| files.view == FileView::Tree && !files.searching)
&& input != self.leader
&& !self.has_sequence_prefix(self.binding_mode(), &input)
&& !self
.bindings
.get(&self.binding_mode())
.is_some_and(|keys| keys.contains_key(&input))
{
return self.execute_action(Action::DiffReviewToggle.entry(), "");
}
if self.sequence_pending().is_some()
|| (phase == Phase::View
&& (input == self.leader || self.has_sequence_prefix(self.binding_mode(), &input)))
@@ -13575,6 +13591,33 @@ mod tests {
assert!(editor.diff().unwrap().reviewed_files.is_empty());
}
#[test]
fn diff_review_c_toggles_only_while_browsing_and_respects_overrides() {
let directory = Directory::new();
let mut editor = editor();
historical_diff(
&mut editor,
&directory.0,
vec!["before".into()],
vec!["after".into()],
);
editor.handle(Input::BackTab);
assert_eq!(editor.diff().unwrap().focus, Focus::Files);
editor.handle(Input::Char('c'));
assert_eq!(editor.diff().unwrap().reviewed_files, BTreeSet::from([0]));
editor.handle(Input::Char('c'));
assert!(editor.diff().unwrap().reviewed_files.is_empty());
editor.handle(Input::Char('i'));
editor.handle(Input::Char('c'));
assert_eq!(editor.diff().unwrap().files.as_ref().unwrap().query, "c");
assert!(editor.diff().unwrap().reviewed_files.is_empty());
editor.handle(Input::Escape);
editor.handle(Input::Ctrl('u'));
editor.bind("normal", "c", None).unwrap();
editor.handle(Input::Char('c'));
assert!(editor.diff().unwrap().reviewed_files.is_empty());
}
#[test]
fn diff_review_files_action_targets_highlight_without_stealing_filter_text() {
let directory = Directory::new();