Fix focus and re-focus of project-wide search
This fixes the issue of `Cmd-shift-f` not refocusing the search bar when a project-wide search already exists. It also fixes the handlers for "search in new" and "new search". Co-authored-by: Kirill <kirill@zed.dev>
This commit is contained in:
parent
b6d8665fc1
commit
130ea79c95
1 changed files with 24 additions and 26 deletions
|
@ -94,31 +94,29 @@ pub fn init(cx: &mut AppContext) {
|
||||||
search_bar.select_next_match(action, cx)
|
search_bar.select_next_match(action, cx)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
register_workspace_action(
|
|
||||||
workspace,
|
|
||||||
move |search_bar, action: &SelectPrevMatch, cx| {
|
|
||||||
search_bar.select_prev_match(action, cx)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
register_workspace_action_for_dismissed_search(
|
// Only handle search_in_new if there is a search present
|
||||||
workspace,
|
register_workspace_action_for_present_search(workspace, |workspace, action, cx| {
|
||||||
move |workspace, action: &NewSearch, cx| {
|
ProjectSearchView::search_in_new(workspace, action, cx)
|
||||||
ProjectSearchView::new_search(workspace, action, cx)
|
});
|
||||||
},
|
|
||||||
);
|
// Both on present and dismissed search, we need to unconditionally handle those actions to focus from the editor.
|
||||||
register_workspace_action_for_dismissed_search(
|
workspace.register_action(move |workspace, action: &DeploySearch, cx| {
|
||||||
workspace,
|
if workspace.has_active_modal(cx) {
|
||||||
move |workspace, action: &DeploySearch, cx| {
|
cx.propagate();
|
||||||
ProjectSearchView::deploy_search(workspace, action, cx)
|
return;
|
||||||
},
|
}
|
||||||
);
|
ProjectSearchView::deploy_search(workspace, action, cx);
|
||||||
register_workspace_action_for_dismissed_search(
|
cx.notify();
|
||||||
workspace,
|
});
|
||||||
move |workspace, action: &SearchInNew, cx| {
|
workspace.register_action(move |workspace, action: &NewSearch, cx| {
|
||||||
ProjectSearchView::search_in_new(workspace, action, cx)
|
if workspace.has_active_modal(cx) {
|
||||||
},
|
cx.propagate();
|
||||||
);
|
return;
|
||||||
|
}
|
||||||
|
ProjectSearchView::new_search(workspace, action, cx);
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
@ -2057,7 +2055,7 @@ fn register_workspace_action<A: Action>(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_workspace_action_for_dismissed_search<A: Action>(
|
fn register_workspace_action_for_present_search<A: Action>(
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
callback: fn(&mut Workspace, &A, &mut ViewContext<Workspace>),
|
callback: fn(&mut Workspace, &A, &mut ViewContext<Workspace>),
|
||||||
) {
|
) {
|
||||||
|
@ -2073,7 +2071,7 @@ fn register_workspace_action_for_dismissed_search<A: Action>(
|
||||||
.toolbar()
|
.toolbar()
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.item_of_type::<ProjectSearchBar>()
|
.item_of_type::<ProjectSearchBar>()
|
||||||
.map(|search_bar| search_bar.read(cx).active_project_search.is_none())
|
.map(|search_bar| search_bar.read(cx).active_project_search.is_some())
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
if should_notify {
|
if should_notify {
|
||||||
callback(workspace, action, cx);
|
callback(workspace, action, cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue