Properly detect file finder label positions in paths (#3931)

Deals with https://github.com/zed-industries/community/issues/2367

Release Notes:

- Fixed file finder crashing on certain paths with multi-codepoint
characters
([#2367](https://github.com/zed-industries/community/issues/2367))
This commit is contained in:
Kirill Bulatov 2024-01-06 23:59:34 +02:00 committed by GitHub
commit ec035724d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -505,8 +505,7 @@ impl FileFinderDelegate {
|| path_match.path_prefix.to_string(),
|file_name| file_name.to_string_lossy().to_string(),
);
let file_name_start = path_match.path_prefix.chars().count() + path_string.chars().count()
- file_name.chars().count();
let file_name_start = path_match.path_prefix.len() + path_string.len() - file_name.len();
let file_name_positions = path_positions
.iter()
.filter_map(|pos| {
@ -819,6 +818,44 @@ mod tests {
}
}
#[gpui::test]
async fn test_complex_path(cx: &mut TestAppContext) {
let app_state = init_test(cx);
app_state
.fs
.as_fake()
.insert_tree(
"/root",
json!({
"其他": {
"S数据表格": {
"task.xlsx": "some content",
},
}
}),
)
.await;
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
let (picker, workspace, cx) = build_find_picker(project, cx);
cx.simulate_input("t");
picker.update(cx, |picker, _| {
assert_eq!(picker.delegate.matches.len(), 1);
assert_eq!(
collect_search_results(picker),
vec![PathBuf::from("其他/S数据表格/task.xlsx")],
)
});
cx.dispatch_action(SelectNext);
cx.dispatch_action(Confirm);
cx.read(|cx| {
let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
assert_eq!(active_editor.read(cx).title(cx), "task.xlsx");
});
}
#[gpui::test]
async fn test_row_column_numbers_query_inside_file(cx: &mut TestAppContext) {
let app_state = init_test(cx);