Trim file_finder input queries
This commit is contained in:
parent
7b76db4b50
commit
1b39916438
2 changed files with 80 additions and 6 deletions
|
@ -518,6 +518,7 @@ impl PickerDelegate for FileFinderDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_matches(&mut self, raw_query: String, cx: &mut ViewContext<FileFinder>) -> Task<()> {
|
fn update_matches(&mut self, raw_query: String, cx: &mut ViewContext<FileFinder>) -> Task<()> {
|
||||||
|
let raw_query = raw_query.trim();
|
||||||
if raw_query.is_empty() {
|
if raw_query.is_empty() {
|
||||||
let project = self.project.read(cx);
|
let project = self.project.read(cx);
|
||||||
self.latest_search_id = post_inc(&mut self.search_count);
|
self.latest_search_id = post_inc(&mut self.search_count);
|
||||||
|
@ -539,7 +540,6 @@ impl PickerDelegate for FileFinderDelegate {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
Task::ready(())
|
Task::ready(())
|
||||||
} else {
|
} else {
|
||||||
let raw_query = &raw_query;
|
|
||||||
let query = PathLikeWithPosition::parse_str(raw_query, |path_like_str| {
|
let query = PathLikeWithPosition::parse_str(raw_query, |path_like_str| {
|
||||||
Ok::<_, std::convert::Infallible>(FileSearchQuery {
|
Ok::<_, std::convert::Infallible>(FileSearchQuery {
|
||||||
raw_query: raw_query.to_owned(),
|
raw_query: raw_query.to_owned(),
|
||||||
|
@ -735,6 +735,7 @@ mod tests {
|
||||||
cx.dispatch_action(window.into(), Toggle);
|
cx.dispatch_action(window.into(), Toggle);
|
||||||
|
|
||||||
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
let finder = cx.read(|cx| workspace.read(cx).modal::<FileFinder>().unwrap());
|
||||||
|
|
||||||
finder
|
finder
|
||||||
.update(cx, |finder, cx| {
|
.update(cx, |finder, cx| {
|
||||||
finder.delegate_mut().update_matches("bna".to_string(), cx)
|
finder.delegate_mut().update_matches("bna".to_string(), cx)
|
||||||
|
@ -743,7 +744,6 @@ mod tests {
|
||||||
finder.read_with(cx, |finder, _| {
|
finder.read_with(cx, |finder, _| {
|
||||||
assert_eq!(finder.delegate().matches.len(), 2);
|
assert_eq!(finder.delegate().matches.len(), 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
||||||
cx.dispatch_action(window.into(), SelectNext);
|
cx.dispatch_action(window.into(), SelectNext);
|
||||||
cx.dispatch_action(window.into(), Confirm);
|
cx.dispatch_action(window.into(), Confirm);
|
||||||
|
@ -762,6 +762,49 @@ mod tests {
|
||||||
"bandana"
|
"bandana"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for bandana_query in [
|
||||||
|
"bandana",
|
||||||
|
" bandana",
|
||||||
|
"bandana ",
|
||||||
|
" bandana ",
|
||||||
|
" ndan ",
|
||||||
|
" band ",
|
||||||
|
] {
|
||||||
|
finder
|
||||||
|
.update(cx, |finder, cx| {
|
||||||
|
finder
|
||||||
|
.delegate_mut()
|
||||||
|
.update_matches(bandana_query.to_string(), cx)
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
finder.read_with(cx, |finder, _| {
|
||||||
|
assert_eq!(
|
||||||
|
finder.delegate().matches.len(),
|
||||||
|
1,
|
||||||
|
"Wrong number of matches for bandana query '{bandana_query}'"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone());
|
||||||
|
cx.dispatch_action(window.into(), SelectNext);
|
||||||
|
cx.dispatch_action(window.into(), Confirm);
|
||||||
|
active_pane
|
||||||
|
.condition(cx, |pane, _| pane.active_item().is_some())
|
||||||
|
.await;
|
||||||
|
cx.read(|cx| {
|
||||||
|
let active_item = active_pane.read(cx).active_item().unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
active_item
|
||||||
|
.as_any()
|
||||||
|
.downcast_ref::<Editor>()
|
||||||
|
.unwrap()
|
||||||
|
.read(cx)
|
||||||
|
.title(cx),
|
||||||
|
"bandana",
|
||||||
|
"Wrong match for bandana query '{bandana_query}'"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
|
|
@ -552,6 +552,7 @@ impl PickerDelegate for FileFinderDelegate {
|
||||||
raw_query: String,
|
raw_query: String,
|
||||||
cx: &mut ViewContext<Picker<Self>>,
|
cx: &mut ViewContext<Picker<Self>>,
|
||||||
) -> Task<()> {
|
) -> Task<()> {
|
||||||
|
let raw_query = raw_query.trim();
|
||||||
if raw_query.is_empty() {
|
if raw_query.is_empty() {
|
||||||
let project = self.project.read(cx);
|
let project = self.project.read(cx);
|
||||||
self.latest_search_id = post_inc(&mut self.search_count);
|
self.latest_search_id = post_inc(&mut self.search_count);
|
||||||
|
@ -573,7 +574,6 @@ impl PickerDelegate for FileFinderDelegate {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
Task::ready(())
|
Task::ready(())
|
||||||
} else {
|
} else {
|
||||||
let raw_query = &raw_query;
|
|
||||||
let query = PathLikeWithPosition::parse_str(raw_query, |path_like_str| {
|
let query = PathLikeWithPosition::parse_str(raw_query, |path_like_str| {
|
||||||
Ok::<_, std::convert::Infallible>(FileSearchQuery {
|
Ok::<_, std::convert::Infallible>(FileSearchQuery {
|
||||||
raw_query: raw_query.to_owned(),
|
raw_query: raw_query.to_owned(),
|
||||||
|
@ -766,18 +766,49 @@ mod tests {
|
||||||
let (picker, workspace, cx) = build_find_picker(project, cx);
|
let (picker, workspace, cx) = build_find_picker(project, cx);
|
||||||
|
|
||||||
cx.simulate_input("bna");
|
cx.simulate_input("bna");
|
||||||
|
|
||||||
picker.update(cx, |picker, _| {
|
picker.update(cx, |picker, _| {
|
||||||
assert_eq!(picker.delegate.matches.len(), 2);
|
assert_eq!(picker.delegate.matches.len(), 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.dispatch_action(SelectNext);
|
cx.dispatch_action(SelectNext);
|
||||||
cx.dispatch_action(Confirm);
|
cx.dispatch_action(Confirm);
|
||||||
|
|
||||||
cx.read(|cx| {
|
cx.read(|cx| {
|
||||||
let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
|
let active_editor = workspace.read(cx).active_item_as::<Editor>(cx).unwrap();
|
||||||
assert_eq!(active_editor.read(cx).title(cx), "bandana");
|
assert_eq!(active_editor.read(cx).title(cx), "bandana");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for bandana_query in [
|
||||||
|
"bandana",
|
||||||
|
" bandana",
|
||||||
|
"bandana ",
|
||||||
|
" bandana ",
|
||||||
|
" ndan ",
|
||||||
|
" band ",
|
||||||
|
] {
|
||||||
|
picker
|
||||||
|
.update(cx, |picker, cx| {
|
||||||
|
picker
|
||||||
|
.delegate
|
||||||
|
.update_matches(bandana_query.to_string(), cx)
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
picker.update(cx, |picker, _| {
|
||||||
|
assert_eq!(
|
||||||
|
picker.delegate.matches.len(),
|
||||||
|
1,
|
||||||
|
"Wrong number of matches for bandana query '{bandana_query}'"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
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),
|
||||||
|
"bandana",
|
||||||
|
"Wrong match for bandana query '{bandana_query}'"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue