WIP pull breadcrumb rendering out into item trait

This commit is contained in:
K Simmons 2022-09-06 14:39:58 -07:00
parent 1014d65e8e
commit ab81093ef5
10 changed files with 176 additions and 159 deletions

View file

@ -191,16 +191,17 @@ impl ToolbarItemView for BufferSearchBar {
if let Some(searchable_item_handle) = item.and_then(|item| item.as_searchable(cx)) {
let handle = cx.weak_handle();
self.active_searchable_item_subscription = Some(searchable_item_handle.subscribe(
cx,
Box::new(move |search_event, cx| {
if let Some(this) = handle.upgrade(cx) {
this.update(cx, |this, cx| {
this.on_active_searchable_item_event(search_event, cx)
});
}
}),
));
self.active_searchable_item_subscription =
Some(searchable_item_handle.subscribe_to_search_events(
cx,
Box::new(move |search_event, cx| {
if let Some(this) = handle.upgrade(cx) {
this.update(cx, |this, cx| {
this.on_active_searchable_item_event(search_event, cx)
});
}
}),
));
self.active_searchable_item = Some(searchable_item_handle);
self.update_matches(false, cx);

View file

@ -24,7 +24,8 @@ use std::{
use util::ResultExt as _;
use workspace::{
searchable::{Direction, SearchableItem, SearchableItemHandle},
Item, ItemHandle, ItemNavHistory, Pane, ToolbarItemLocation, ToolbarItemView, Workspace,
Item, ItemEvent, ItemHandle, ItemNavHistory, Pane, ToolbarItemLocation, ToolbarItemView,
Workspace,
};
actions!(project_search, [SearchInNew, ToggleFocus]);
@ -326,15 +327,11 @@ impl Item for ProjectSearchView {
.update(cx, |editor, cx| editor.navigate(data, cx))
}
fn should_update_tab_on_event(event: &ViewEvent) -> bool {
matches!(event, ViewEvent::UpdateTab)
}
fn is_edit_event(event: &Self::Event) -> bool {
if let ViewEvent::EditorEvent(editor_event) = event {
Editor::is_edit_event(editor_event)
} else {
false
fn to_item_events(event: &Self::Event) -> Vec<ItemEvent> {
match event {
ViewEvent::UpdateTab => vec![ItemEvent::UpdateTab],
ViewEvent::EditorEvent(editor_event) => Editor::to_item_events(editor_event),
_ => Vec::new(),
}
}
}