fix: focus After when opening a diff file
This commit is contained in:
+52
-2
@@ -1151,7 +1151,8 @@ impl DiffState {
|
||||
if let Some(path) = files.accept()
|
||||
&& self.select_file(&path)
|
||||
{
|
||||
self.focus = self.first_text_focus();
|
||||
self.focus = Focus::After;
|
||||
self.normalize_focus();
|
||||
let files = self.files.as_mut().expect("comparison picker");
|
||||
files.focused = false;
|
||||
self.files_visible = files.presentation == FilePresentation::Docked;
|
||||
@@ -3205,6 +3206,55 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_diff_file_focuses_after_when_present() {
|
||||
for view_mode in [ViewMode::Split, ViewMode::Unified] {
|
||||
for presentation in [FilePresentation::Docked, FilePresentation::Floating] {
|
||||
for status in [
|
||||
FileStatus::Modified,
|
||||
FileStatus::Renamed,
|
||||
FileStatus::Added,
|
||||
FileStatus::Removed,
|
||||
] {
|
||||
let mut editor = editor();
|
||||
editor.set_diff_display_options(view_mode, crate::panes::SplitAxis::Vertical);
|
||||
open(&mut editor);
|
||||
let id = choose_pair(&mut editor);
|
||||
let mut changes = comparison();
|
||||
let index = match status {
|
||||
FileStatus::Modified | FileStatus::Renamed => 0,
|
||||
FileStatus::Added => 1,
|
||||
FileStatus::Removed => 2,
|
||||
};
|
||||
let mut file = changes.files.remove(index);
|
||||
file.status = status;
|
||||
let expected_text = file.after.join("\n");
|
||||
changes.files = vec![file];
|
||||
editor.apply_diff_result(id, Ok(Outcome::Comparison(changes)));
|
||||
if presentation == FilePresentation::Floating {
|
||||
text(&mut editor, " o");
|
||||
}
|
||||
editor.handle(Input::Enter);
|
||||
let diff = editor.diff().unwrap();
|
||||
assert_eq!(
|
||||
diff.focus,
|
||||
if status == FileStatus::Removed {
|
||||
Focus::Before
|
||||
} else {
|
||||
Focus::After
|
||||
},
|
||||
"{view_mode:?} {presentation:?} {status:?}",
|
||||
);
|
||||
assert!(!diff.files.as_ref().unwrap().focused);
|
||||
assert_eq!(diff.files_visible, presentation == FilePresentation::Docked);
|
||||
if status != FileStatus::Removed {
|
||||
assert_eq!(editor.context().text, expected_text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn added_file_picker_cancel_close_and_mouse_focus_use_after() {
|
||||
let mut editor = editor();
|
||||
@@ -3509,7 +3559,7 @@ mod tests {
|
||||
assert!(!picker.entries().nth(picker.selected).unwrap().is_dir);
|
||||
editor.handle(Input::Enter);
|
||||
assert_eq!(editor.diff().unwrap().file, 0);
|
||||
editor.handle(Input::BackTab);
|
||||
text(&mut editor, " e");
|
||||
editor.handle(Input::Char('i'));
|
||||
text(&mut editor, "x/y");
|
||||
editor.handle(Input::Enter);
|
||||
|
||||
@@ -8675,6 +8675,7 @@ mod tests {
|
||||
let mut diff = diff_comparison(vec![deletion_file(), added]);
|
||||
diff.handle(Input::Down);
|
||||
diff.handle(Input::Enter);
|
||||
diff.handle(Input::BackTab);
|
||||
for _ in 0..4 {
|
||||
diff.handle(Input::Right);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user