Merge pull request #791 from zed-industries/project-search-focus-fix

Properly activate project search item on mouse click
This commit is contained in:
Max Brunsfeld 2022-04-11 17:31:06 -07:00 committed by GitHub
commit 2807d85a60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -136,6 +136,7 @@ impl ProjectSearch {
pub enum ViewEvent {
UpdateTab,
EditorEvent(editor::Event),
}
impl Entity for ProjectSearchView {
@ -304,6 +305,14 @@ impl Item for ProjectSearchView {
.update(cx, |editor, cx| editor.navigate(data, cx))
}
fn should_activate_item_on_event(event: &Self::Event) -> bool {
if let ViewEvent::EditorEvent(editor_event) = event {
Editor::should_activate_item_on_event(editor_event)
} else {
false
}
}
fn should_update_tab_on_event(event: &ViewEvent) -> bool {
matches!(event, ViewEvent::UpdateTab)
}
@ -338,6 +347,11 @@ impl ProjectSearchView {
editor.set_text(query_text, cx);
editor
});
// Subcribe to query_editor in order to reraise editor events for workspace item activation purposes
cx.subscribe(&query_editor, |_, _, event, cx| {
cx.emit(ViewEvent::EditorEvent(event.clone()))
})
.detach();
let results_editor = cx.add_view(|cx| {
let mut editor = Editor::for_multibuffer(excerpts, Some(project), cx);
@ -350,6 +364,8 @@ impl ProjectSearchView {
if matches!(event, editor::Event::SelectionsChanged { .. }) {
this.update_match_index(cx);
}
// Reraise editor events for workspace item activation purposes
cx.emit(ViewEvent::EditorEvent(event.clone()));
})
.detach();