From 25ad635577bc0201eba5d924862e32c4eaeed6bf Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 12 Apr 2023 12:38:26 -0600 Subject: [PATCH] WIP --- crates/breadcrumbs/src/breadcrumbs.rs | 16 ++++++++++-- crates/copilot_button/src/copilot_button.rs | 3 +-- crates/editor/src/items.rs | 27 +++++++-------------- crates/search/src/project_search.rs | 12 +++------ crates/terminal_view/src/terminal_view.rs | 23 ++++++------------ crates/workspace/src/item.rs | 19 +++++++++------ 6 files changed, 47 insertions(+), 53 deletions(-) diff --git a/crates/breadcrumbs/src/breadcrumbs.rs b/crates/breadcrumbs/src/breadcrumbs.rs index bce7f7d11e..ce36e440ad 100644 --- a/crates/breadcrumbs/src/breadcrumbs.rs +++ b/crates/breadcrumbs/src/breadcrumbs.rs @@ -54,10 +54,22 @@ impl View for Breadcrumbs { let breadcrumbs = match active_item.breadcrumbs(&theme, cx) { Some(breadcrumbs) => breadcrumbs, None => return Empty::new().boxed(), - }; + } + .into_iter() + .map(|breadcrumb| { + let text = Text::new( + breadcrumb.text, + theme.workspace.breadcrumbs.default.text.clone(), + ); + if let Some(highlights) = breadcrumb.highlights { + text.with_highlights(highlights).boxed() + } else { + text.boxed() + } + }); let crumbs = Flex::row() - .with_children(Itertools::intersperse_with(breadcrumbs.into_iter(), || { + .with_children(Itertools::intersperse_with(breadcrumbs, || { Label::new(" 〉 ", style.default.text.clone()).boxed() })) .constrained() diff --git a/crates/copilot_button/src/copilot_button.rs b/crates/copilot_button/src/copilot_button.rs index 8a383ce980..072de103d1 100644 --- a/crates/copilot_button/src/copilot_button.rs +++ b/crates/copilot_button/src/copilot_button.rs @@ -6,8 +6,7 @@ use gpui::{ elements::*, impl_internal_actions, platform::{CursorStyle, MouseButton}, - AppContext, Drawable, Element, Entity, MouseState, Subscription, View, ViewContext, - ViewHandle, + AppContext, Drawable, Element, Entity, MouseState, Subscription, View, ViewContext, ViewHandle, }; use settings::{settings_file::SettingsFile, Settings}; use workspace::{ diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index dc2a604f28..a39e6fbceb 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -28,7 +28,7 @@ use std::{ }; use text::Selection; use util::{ResultExt, TryFutureExt}; -use workspace::item::FollowableItemHandle; +use workspace::item::{BreadcrumbText, FollowableItemHandle}; use workspace::{ item::{FollowableItem, Item, ItemEvent, ItemHandle, ProjectItem}, searchable::{Direction, SearchEvent, SearchableItem, SearchableItemHandle}, @@ -727,11 +727,7 @@ impl Item for Editor { ToolbarItemLocation::PrimaryLeft { flex: None } } - fn breadcrumbs( - &self, - theme: &theme::Theme, - cx: &AppContext, - ) -> Option>> { + fn breadcrumbs(&self, theme: &theme::Theme, cx: &AppContext) -> Option> { let cursor = self.selections.newest_anchor().head(); let multibuffer = &self.buffer().read(cx); let (buffer_id, symbols) = @@ -751,18 +747,13 @@ impl Item for Editor { .map(|path| path.to_string_lossy().to_string()) .unwrap_or_else(|| "untitled".to_string()); - let filename_label = Label::new(filename, theme.workspace.breadcrumbs.default.text.clone()); - let mut breadcrumbs = - vec![Box::new(filename_label.into_root(cx)) as Box]; - breadcrumbs.extend(symbols.into_iter().map(|symbol| { - Box::new( - Text::new( - symbol.text, - theme.workspace.breadcrumbs.default.text.clone(), - ) - .with_highlights(symbol.highlight_ranges) - .into_root(cx) as Element, - ) as Box + let mut breadcrumbs = vec![BreadcrumbText { + text: filename, + highlights: None, + }]; + breadcrumbs.extend(symbols.into_iter().map(|symbol| BreadcrumbText { + text: symbol.text, + highlights: Some(symbol.highlight_ranges), })); Some(breadcrumbs) } diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 1eee2b1922..3cbafefa5a 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -12,8 +12,8 @@ use gpui::{ actions, elements::*, platform::{CursorStyle, MouseButton}, - Action, AnyViewHandle, AppContext, Element, Entity, ModelContext, ModelHandle, RenderedView, - Subscription, Task, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle, + Action, AnyViewHandle, AppContext, Element, Entity, ModelContext, ModelHandle, Subscription, + Task, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle, }; use menu::Confirm; use project::{search::SearchQuery, Project}; @@ -28,7 +28,7 @@ use std::{ }; use util::ResultExt as _; use workspace::{ - item::{Item, ItemEvent, ItemHandle}, + item::{BreadcrumbText, Item, ItemEvent, ItemHandle}, searchable::{Direction, SearchableItem, SearchableItemHandle}, ItemNavHistory, Pane, ToolbarItemLocation, ToolbarItemView, Workspace, WorkspaceId, }; @@ -364,11 +364,7 @@ impl Item for ProjectSearchView { } } - fn breadcrumbs( - &self, - theme: &theme::Theme, - cx: &AppContext, - ) -> Option>> { + fn breadcrumbs(&self, theme: &theme::Theme, cx: &AppContext) -> Option> { self.results_editor.breadcrumbs(theme, cx) } diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index dca9a81f51..eef6859c80 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -17,8 +17,8 @@ use gpui::{ impl_actions, impl_internal_actions, keymap_matcher::{KeymapContext, Keystroke}, platform::KeyDownEvent, - AnyViewHandle, AppContext, Drawable, Element, Entity, ModelHandle, RenderedView, Task, View, - ViewContext, ViewHandle, WeakViewHandle, + AnyViewHandle, AppContext, Drawable, Element, Entity, ModelHandle, Task, View, ViewContext, + ViewHandle, WeakViewHandle, }; use project::{LocalWorktree, Project}; use serde::Deserialize; @@ -34,7 +34,7 @@ use terminal::{ }; use util::ResultExt; use workspace::{ - item::{Item, ItemEvent}, + item::{BreadcrumbText, Item, ItemEvent}, notifications::NotifyResultExt, pane, register_deserializable_item, searchable::{SearchEvent, SearchOptions, SearchableItem, SearchableItemHandle}, @@ -606,18 +606,11 @@ impl Item for TerminalView { ToolbarItemLocation::PrimaryLeft { flex: None } } - fn breadcrumbs( - &self, - theme: &theme::Theme, - cx: &AppContext, - ) -> Option>> { - Some(vec![Box::new( - Text::new( - self.terminal().read(cx).breadcrumb_text.clone(), - theme.workspace.breadcrumbs.default.text.clone(), - ) - .boxed() as Element, - )]) + fn breadcrumbs(&self, _: &theme::Theme, cx: &AppContext) -> Option> { + Some(vec![BreadcrumbText { + text: self.terminal().read(cx).breadcrumb_text.clone(), + highlights: None, + }]) } fn serialized_item_kind() -> Option<&'static str> { diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index 85bf1d58d8..6929ef6c28 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -3,6 +3,7 @@ use std::{ borrow::Cow, cell::RefCell, fmt, + ops::Range, path::PathBuf, rc::Rc, sync::{ @@ -15,7 +16,7 @@ use std::{ use anyhow::Result; use client::{proto, Client}; use gpui::{ - elements::AnyRootElement, AnyViewHandle, AppContext, Element, ModelHandle, Task, View, + fonts::HighlightStyle, AnyViewHandle, AppContext, Element, ModelHandle, Task, View, ViewContext, ViewHandle, WeakViewHandle, }; use project::{Project, ProjectEntryId, ProjectPath}; @@ -38,6 +39,12 @@ pub enum ItemEvent { Edit, } +// TODO: Combine this with existing HighlightedText struct? +pub struct BreadcrumbText { + pub text: String, + pub highlights: Option, HighlightStyle)>>, +} + pub trait Item: View { fn deactivated(&mut self, _: &mut ViewContext) {} fn workspace_deactivated(&mut self, _: &mut ViewContext) {} @@ -134,11 +141,7 @@ pub trait Item: View { ToolbarItemLocation::Hidden } - fn breadcrumbs( - &self, - _theme: &Theme, - _cx: &ViewContext, - ) -> Option>> { + fn breadcrumbs(&self, _theme: &Theme, _cx: &AppContext) -> Option> { None } @@ -225,7 +228,7 @@ pub trait ItemHandle: 'static + fmt::Debug { ) -> gpui::Subscription; fn to_searchable_item_handle(&self, cx: &AppContext) -> Option>; fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation; - fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option>>; + fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option>; fn serialized_item_kind(&self) -> Option<&'static str>; fn show_toolbar(&self, cx: &AppContext) -> bool; } @@ -595,7 +598,7 @@ impl ItemHandle for ViewHandle { self.read(cx).breadcrumb_location() } - fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option>> { + fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option> { self.read(cx).breadcrumbs(theme, cx) }