Refactor file_finder send element open code (#7210)
Follow-up of https://github.com/zed-industries/zed/pull/6947 (cc @alygin) that fixes a few style nits and refactors the code around: * use already stored `currently_opened_path` to decide what to do with the history item sorting * use the same method to set history items, encapsulate the bubbling up logic there * ensure history elements are properly sorted before populating The main reason to change all that is the new comparator in the previous version: https://github.com/zed-industries/zed/pull/6947/files#diff-eac7c8c99856f77cee39117708cd1467fd5bbc8805da2564f851951638020842R234 that almost violated `util::extend_sorted` contract, requiring both collections to be sorted the same way as the comparator would be: it did work, because we bubbled currently open item up in the history items list manually, and that we have only one such item. Release Notes: - N/A
This commit is contained in:
parent
0edffd9248
commit
0102ffbfca
4 changed files with 101 additions and 94 deletions
|
@ -1126,6 +1126,7 @@ async fn test_keep_opened_file_on_top_of_search_results_and_select_next_one(
|
|||
assert_eq!(finder.delegate.matches.len(), 3);
|
||||
assert_match_at_position(finder, 0, "main.rs");
|
||||
assert_match_selection(finder, 1, "lib.rs");
|
||||
assert_match_at_position(finder, 2, "bar.rs");
|
||||
});
|
||||
|
||||
// all files match, main.rs is still on top
|
||||
|
@ -1446,15 +1447,21 @@ fn collect_search_matches(picker: &Picker<FileFinderDelegate>) -> SearchEntries
|
|||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn assert_match_selection(
|
||||
finder: &Picker<FileFinderDelegate>,
|
||||
expected_selection_index: usize,
|
||||
expected_file_name: &str,
|
||||
) {
|
||||
assert_eq!(finder.delegate.selected_index(), expected_selection_index);
|
||||
assert_eq!(
|
||||
finder.delegate.selected_index(),
|
||||
expected_selection_index,
|
||||
"Match is not selected"
|
||||
);
|
||||
assert_match_at_position(finder, expected_selection_index, expected_file_name);
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn assert_match_at_position(
|
||||
finder: &Picker<FileFinderDelegate>,
|
||||
match_index: usize,
|
||||
|
@ -1464,11 +1471,12 @@ fn assert_match_at_position(
|
|||
.delegate
|
||||
.matches
|
||||
.get(match_index)
|
||||
.expect("Finder should have a match item with the given index");
|
||||
.unwrap_or_else(|| panic!("Finder has no match for index {match_index}"));
|
||||
let match_file_name = match match_item {
|
||||
Match::History(found_path, _) => found_path.absolute.as_deref().unwrap().file_name(),
|
||||
Match::Search(path_match) => path_match.0.path.file_name(),
|
||||
};
|
||||
let match_file_name = match_file_name.unwrap().to_string_lossy().to_string();
|
||||
assert_eq!(match_file_name.as_str(), expected_file_name);
|
||||
}
|
||||
.unwrap()
|
||||
.to_string_lossy();
|
||||
assert_eq!(match_file_name, expected_file_name);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue