Detailed changes
@@ -1,14 +1,15 @@
use gpui::{
- AnyElement, App, Context, EventEmitter, Global, IntoElement, Render, Subscription, Window,
+ AnyElement, App, Context, EventEmitter, Font, Global, IntoElement, Render, Subscription, Window,
};
use ui::prelude::*;
use workspace::{
ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView,
- item::{BreadcrumbText, ItemEvent, ItemHandle},
+ item::{HighlightedText, ItemEvent, ItemHandle},
};
type RenderBreadcrumbTextFn = fn(
- Vec<BreadcrumbText>,
+ Vec<HighlightedText>,
+ Option<Font>,
Option<AnyElement>,
&dyn ItemHandle,
bool,
@@ -57,7 +58,7 @@ impl Render for Breadcrumbs {
return element.into_any_element();
};
- let Some(segments) = active_item.breadcrumbs(cx) else {
+ let Some((segments, breadcrumb_font)) = active_item.breadcrumbs(cx) else {
return element.into_any_element();
};
@@ -66,6 +67,7 @@ impl Render for Breadcrumbs {
if let Some(render_fn) = cx.try_global::<RenderBreadcrumbText>() {
(render_fn.0)(
segments,
+ breadcrumb_font,
prefix_element,
active_item.as_ref(),
false,
@@ -5691,7 +5691,7 @@ async fn test_document_symbols(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont
executor.run_until_parked();
editor_a.update(cx_a, |editor, cx| {
- let breadcrumbs = editor
+ let (breadcrumbs, _) = editor
.breadcrumbs(cx)
.expect("Host should have breadcrumbs");
let texts: Vec<_> = breadcrumbs.iter().map(|b| b.text.as_str()).collect();
@@ -5727,6 +5727,7 @@ async fn test_document_symbols(cx_a: &mut TestAppContext, cx_b: &mut TestAppCont
editor
.breadcrumbs(cx)
.expect("Client B should have breadcrumbs")
+ .0
.iter()
.map(|b| b.text.as_str())
.collect::<Vec<_>>(),
@@ -217,7 +217,7 @@ use workspace::{
CollaboratorId, Item as WorkspaceItem, ItemId, ItemNavHistory, NavigationEntry, OpenInTerminal,
OpenTerminal, Pane, RestoreOnStartupBehavior, SERIALIZATION_THROTTLE_TIME, SplitDirection,
TabBarSettings, Toast, ViewId, Workspace, WorkspaceId, WorkspaceSettings,
- item::{BreadcrumbText, ItemBufferKind, ItemHandle, PreviewTabsSettings, SaveOptions},
+ item::{ItemBufferKind, ItemHandle, PreviewTabsSettings, SaveOptions},
notifications::{DetachAndPromptErr, NotificationId, NotifyTaskExt},
searchable::SearchEvent,
};
@@ -25323,14 +25323,13 @@ impl Editor {
}
}
- fn breadcrumbs_inner(&self, cx: &App) -> Option<Vec<BreadcrumbText>> {
+ fn breadcrumbs_inner(&self, cx: &App) -> Option<Vec<HighlightedText>> {
let multibuffer = self.buffer().read(cx);
let is_singleton = multibuffer.is_singleton();
let (buffer_id, symbols) = self.outline_symbols_at_cursor.as_ref()?;
let buffer = multibuffer.buffer(*buffer_id)?;
let buffer = buffer.read(cx);
- let settings = ThemeSettings::get_global(cx);
// In a multi-buffer layout, we don't want to include the filename in the breadcrumbs
let mut breadcrumbs = if is_singleton {
let text = self.breadcrumb_header.clone().unwrap_or_else(|| {
@@ -25351,19 +25350,17 @@ impl Editor {
}
})
});
- vec![BreadcrumbText {
- text,
- highlights: None,
- font: Some(settings.buffer_font.clone()),
+ vec![HighlightedText {
+ text: text.into(),
+ highlights: vec![],
}]
} else {
vec![]
};
- breadcrumbs.extend(symbols.iter().map(|symbol| BreadcrumbText {
- text: symbol.text.clone(),
- highlights: Some(symbol.highlight_ranges.clone()),
- font: Some(settings.buffer_font.clone()),
+ breadcrumbs.extend(symbols.iter().map(|symbol| HighlightedText {
+ text: symbol.text.clone().into(),
+ highlights: symbol.highlight_ranges.clone(),
}));
Some(breadcrumbs)
}
@@ -41,18 +41,18 @@ use git::{Oid, blame::BlameEntry, commit::ParsedCommitMessage, status::FileStatu
use gpui::{
Action, Along, AnyElement, App, AppContext, AvailableSpace, Axis as ScrollbarAxis, BorderStyle,
Bounds, ClickEvent, ClipboardItem, ContentMask, Context, Corner, Corners, CursorStyle,
- DispatchPhase, Edges, Element, ElementInputHandler, Entity, Focusable as _, FontId, FontWeight,
- GlobalElementId, Hitbox, HitboxBehavior, Hsla, InteractiveElement, IntoElement, IsZero,
- KeybindingKeystroke, Length, Modifiers, ModifiersChangedEvent, MouseButton, MouseClickEvent,
- MouseDownEvent, MouseMoveEvent, MousePressureEvent, MouseUpEvent, PaintQuad, ParentElement,
- Pixels, PressureStage, ScrollDelta, ScrollHandle, ScrollWheelEvent, ShapedLine, SharedString,
- Size, StatefulInteractiveElement, Style, Styled, StyledText, TextAlign, TextRun,
+ DispatchPhase, Edges, Element, ElementInputHandler, Entity, Focusable as _, Font, FontId,
+ FontWeight, GlobalElementId, Hitbox, HitboxBehavior, Hsla, InteractiveElement, IntoElement,
+ IsZero, KeybindingKeystroke, Length, Modifiers, ModifiersChangedEvent, MouseButton,
+ MouseClickEvent, MouseDownEvent, MouseMoveEvent, MousePressureEvent, MouseUpEvent, PaintQuad,
+ ParentElement, Pixels, PressureStage, ScrollDelta, ScrollHandle, ScrollWheelEvent, ShapedLine,
+ SharedString, Size, StatefulInteractiveElement, Style, Styled, StyledText, TextAlign, TextRun,
TextStyleRefinement, WeakEntity, Window, anchored, deferred, div, fill, linear_color_stop,
linear_gradient, outline, pattern_slash, point, px, quad, relative, size, solid_background,
transparent_black,
};
use itertools::Itertools;
-use language::{IndentGuideSettings, language_settings::ShowWhitespaceSetting};
+use language::{HighlightedText, IndentGuideSettings, language_settings::ShowWhitespaceSetting};
use markdown::Markdown;
use multi_buffer::{
Anchor, ExcerptId, ExcerptInfo, ExpandExcerptDirection, ExpandInfo, MultiBufferPoint,
@@ -98,7 +98,7 @@ use util::{RangeExt, ResultExt, debug_panic};
use workspace::{
CollaboratorId, ItemHandle, ItemSettings, OpenInTerminal, OpenTerminal, RevealInProjectPanel,
Workspace,
- item::{BreadcrumbText, Item, ItemBufferKind},
+ item::{Item, ItemBufferKind},
};
/// Determines what kinds of highlights should be applied to a lines background.
@@ -7913,7 +7913,8 @@ impl EditorElement {
}
pub fn render_breadcrumb_text(
- mut segments: Vec<BreadcrumbText>,
+ mut segments: Vec<HighlightedText>,
+ breadcrumb_font: Option<Font>,
prefix: Option<gpui::AnyElement>,
active_item: &dyn ItemHandle,
multibuffer_header: bool,
@@ -7933,17 +7934,16 @@ pub fn render_breadcrumb_text(
if suffix_start_ix > prefix_end_ix {
segments.splice(
prefix_end_ix..suffix_start_ix,
- Some(BreadcrumbText {
+ Some(HighlightedText {
text: "⋯".into(),
- highlights: None,
- font: None,
+ highlights: vec![],
}),
);
}
let highlighted_segments = segments.into_iter().enumerate().map(|(index, segment)| {
let mut text_style = window.text_style();
- if let Some(ref font) = segment.font {
+ if let Some(font) = &breadcrumb_font {
text_style.font_family = font.family.clone();
text_style.font_features = font.features.clone();
text_style.font_style = font.style;
@@ -7960,7 +7960,7 @@ pub fn render_breadcrumb_text(
}
StyledText::new(segment.text.replace('\n', " "))
- .with_default_highlights(&text_style, segment.highlights.unwrap_or_default())
+ .with_default_highlights(&text_style, segment.highlights)
.into_any()
});
@@ -8070,13 +8070,13 @@ pub fn render_breadcrumb_text(
}
fn apply_dirty_filename_style(
- segment: &BreadcrumbText,
+ segment: &HighlightedText,
text_style: &gpui::TextStyle,
cx: &App,
) -> Option<gpui::AnyElement> {
let text = segment.text.replace('\n', " ");
- let filename_position = std::path::Path::new(&segment.text)
+ let filename_position = std::path::Path::new(segment.text.as_ref())
.file_name()
.and_then(|f| {
let filename_str = f.to_string_lossy();
@@ -8446,8 +8446,12 @@ pub(crate) fn render_buffer_header(
el.child(Icon::new(IconName::FileLock).color(Color::Muted))
})
.when_some(breadcrumbs, |then, breadcrumbs| {
+ let font = theme::ThemeSettings::get_global(cx)
+ .buffer_font
+ .clone();
then.child(render_breadcrumb_text(
breadcrumbs,
+ Some(font),
None,
editor_handle,
true,
@@ -14,12 +14,12 @@ use fs::MTime;
use futures::future::try_join_all;
use git::status::GitSummary;
use gpui::{
- AnyElement, App, AsyncWindowContext, Context, Entity, EntityId, EventEmitter, IntoElement,
- ParentElement, Pixels, SharedString, Styled, Task, WeakEntity, Window, point,
+ AnyElement, App, AsyncWindowContext, Context, Entity, EntityId, EventEmitter, Font,
+ IntoElement, ParentElement, Pixels, SharedString, Styled, Task, WeakEntity, Window, point,
};
use language::{
- Bias, Buffer, BufferRow, CharKind, CharScopeContext, LocalFile, Point, SelectionGoal,
- proto::serialize_anchor as serialize_text_anchor,
+ Bias, Buffer, BufferRow, CharKind, CharScopeContext, HighlightedText, LocalFile, Point,
+ SelectionGoal, proto::serialize_anchor as serialize_text_anchor,
};
use lsp::DiagnosticSeverity;
use multi_buffer::MultiBufferOffset;
@@ -56,7 +56,7 @@ use workspace::{
};
use workspace::{
OpenVisible, Pane, WorkspaceSettings,
- item::{BreadcrumbText, FollowEvent, ProjectItemKind},
+ item::{FollowEvent, ProjectItemKind},
searchable::SearchOptions,
};
use zed_actions::preview::{
@@ -981,9 +981,10 @@ impl Item for Editor {
}
// In a non-singleton case, the breadcrumbs are actually shown on sticky file headers of the multibuffer.
- fn breadcrumbs(&self, cx: &App) -> Option<Vec<BreadcrumbText>> {
+ fn breadcrumbs(&self, cx: &App) -> Option<(Vec<HighlightedText>, Option<Font>)> {
if self.buffer.read(cx).is_singleton() {
- self.breadcrumbs_inner(cx)
+ let font = theme::ThemeSettings::get_global(cx).buffer_font.clone();
+ Some((self.breadcrumbs_inner(cx)?, Some(font)))
} else {
None
}
@@ -6,9 +6,11 @@ use std::{
use buffer_diff::{BufferDiff, BufferDiffSnapshot};
use collections::HashMap;
-use gpui::{Action, AppContext as _, Entity, EventEmitter, Focusable, Subscription, WeakEntity};
+use gpui::{
+ Action, AppContext as _, Entity, EventEmitter, Focusable, Font, Subscription, WeakEntity,
+};
use itertools::Itertools;
-use language::{Buffer, Capability};
+use language::{Buffer, Capability, HighlightedText};
use multi_buffer::{
Anchor, BufferOffset, ExcerptId, ExcerptRange, ExpandExcerptDirection, MultiBuffer,
MultiBufferDiffHunk, MultiBufferPoint, MultiBufferSnapshot, PathKey,
@@ -29,7 +31,7 @@ use crate::{
};
use workspace::{
ActivatePaneLeft, ActivatePaneRight, Item, ToolbarItemLocation, Workspace,
- item::{BreadcrumbText, ItemBufferKind, ItemEvent, SaveOptions, TabContentParams},
+ item::{ItemBufferKind, ItemEvent, SaveOptions, TabContentParams},
searchable::{SearchEvent, SearchToken, SearchableItem, SearchableItemHandle},
};
@@ -1853,7 +1855,7 @@ impl Item for SplittableEditor {
self.rhs_editor.read(cx).breadcrumb_location(cx)
}
- fn breadcrumbs(&self, cx: &App) -> Option<Vec<BreadcrumbText>> {
+ fn breadcrumbs(&self, cx: &App) -> Option<(Vec<HighlightedText>, Option<Font>)> {
self.rhs_editor.read(cx).breadcrumbs(cx)
}
@@ -6,9 +6,9 @@ use editor::{Editor, EditorEvent, MultiBuffer};
use futures::{FutureExt, select_biased};
use gpui::{
AnyElement, App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, FocusHandle,
- Focusable, IntoElement, Render, Task, WeakEntity, Window,
+ Focusable, Font, IntoElement, Render, Task, WeakEntity, Window,
};
-use language::{Buffer, LanguageRegistry};
+use language::{Buffer, HighlightedText, LanguageRegistry};
use project::Project;
use std::{
any::{Any, TypeId},
@@ -21,7 +21,7 @@ use ui::{Color, Icon, IconName, Label, LabelCommon as _, SharedString};
use util::paths::PathExt as _;
use workspace::{
Item, ItemHandle as _, ItemNavHistory, ToolbarItemLocation, Workspace,
- item::{BreadcrumbText, ItemEvent, SaveOptions, TabContentParams},
+ item::{ItemEvent, SaveOptions, TabContentParams},
searchable::SearchableItemHandle,
};
@@ -324,7 +324,7 @@ impl Item for FileDiffView {
ToolbarItemLocation::PrimaryLeft
}
- fn breadcrumbs(&self, cx: &App) -> Option<Vec<BreadcrumbText>> {
+ fn breadcrumbs(&self, cx: &App) -> Option<(Vec<HighlightedText>, Option<Font>)> {
self.editor.breadcrumbs(cx)
}
@@ -565,7 +565,10 @@ impl Item for FileHistoryView {
false
}
- fn breadcrumbs(&self, _cx: &App) -> Option<Vec<workspace::item::BreadcrumbText>> {
+ fn breadcrumbs(
+ &self,
+ _cx: &App,
+ ) -> Option<(Vec<workspace::item::HighlightedText>, Option<gpui::Font>)> {
None
}
@@ -3,9 +3,9 @@ use buffer_diff::BufferDiff;
use editor::{Editor, EditorEvent, MultiBuffer, multibuffer_context_lines};
use gpui::{
AnyElement, App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, FocusHandle,
- Focusable, IntoElement, Render, SharedString, Task, Window,
+ Focusable, Font, IntoElement, Render, SharedString, Task, Window,
};
-use language::{Buffer, Capability, OffsetRangeExt};
+use language::{Buffer, Capability, HighlightedText, OffsetRangeExt};
use multi_buffer::PathKey;
use project::Project;
use std::{
@@ -18,7 +18,7 @@ use util::paths::PathStyle;
use util::rel_path::RelPath;
use workspace::{
Item, ItemHandle as _, ItemNavHistory, ToolbarItemLocation, Workspace,
- item::{BreadcrumbText, ItemEvent, SaveOptions, TabContentParams},
+ item::{ItemEvent, SaveOptions, TabContentParams},
searchable::SearchableItemHandle,
};
@@ -338,7 +338,7 @@ impl Item for MultiDiffView {
ToolbarItemLocation::PrimaryLeft
}
- fn breadcrumbs(&self, cx: &App) -> Option<Vec<BreadcrumbText>> {
+ fn breadcrumbs(&self, cx: &App) -> Option<(Vec<HighlightedText>, Option<Font>)> {
self.editor.breadcrumbs(cx)
}
@@ -10,10 +10,10 @@ use file_icons::FileIcons;
use gpui::PinchEvent;
use gpui::{
AnyElement, App, Bounds, Context, DispatchPhase, Element, ElementId, Entity, EventEmitter,
- FocusHandle, Focusable, GlobalElementId, InspectorElementId, InteractiveElement, IntoElement,
- LayoutId, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement, Pixels,
- Point, Render, ScrollDelta, ScrollWheelEvent, Style, Styled, Task, WeakEntity, Window, actions,
- checkerboard, div, img, point, px, size,
+ FocusHandle, Focusable, Font, GlobalElementId, InspectorElementId, InteractiveElement,
+ IntoElement, LayoutId, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
+ ParentElement, Pixels, Point, Render, ScrollDelta, ScrollWheelEvent, Style, Styled, Task,
+ WeakEntity, Window, actions, checkerboard, div, img, point, px, size,
};
use language::File as _;
use persistence::IMAGE_VIEWER;
@@ -26,7 +26,7 @@ use workspace::{
ItemId, ItemSettings, Pane, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
WorkspaceId, delete_unloaded_items,
invalid_item_view::InvalidItemView,
- item::{BreadcrumbText, Item, ItemHandle, ProjectItem, SerializableItem, TabContentParams},
+ item::{HighlightedText, Item, ItemHandle, ProjectItem, SerializableItem, TabContentParams},
};
pub use crate::image_info::*;
@@ -530,15 +530,17 @@ impl Item for ImageView {
}
}
- fn breadcrumbs(&self, cx: &App) -> Option<Vec<BreadcrumbText>> {
+ fn breadcrumbs(&self, cx: &App) -> Option<(Vec<HighlightedText>, Option<Font>)> {
let text = breadcrumbs_text_for_image(self.project.read(cx), self.image_item.read(cx), cx);
- let settings = ThemeSettings::get_global(cx);
-
- Some(vec![BreadcrumbText {
- text,
- highlights: None,
- font: Some(settings.buffer_font.clone()),
- }])
+ let font = ThemeSettings::get_global(cx).buffer_font.clone();
+
+ Some((
+ vec![HighlightedText {
+ text: text.into(),
+ highlights: vec![],
+ }],
+ Some(font),
+ ))
}
fn can_split(&self) -> bool {
@@ -9,7 +9,7 @@ use assistant_slash_command::SlashCommandRegistry;
use editor::{Editor, EditorSettings, actions::SelectAll, blink_manager::BlinkManager};
use gpui::{
Action, AnyElement, App, ClipboardEntry, DismissEvent, Entity, EventEmitter, ExternalPaths,
- FocusHandle, Focusable, KeyContext, KeyDownEvent, Keystroke, MouseButton, MouseDownEvent,
+ FocusHandle, Focusable, Font, KeyContext, KeyDownEvent, Keystroke, MouseButton, MouseDownEvent,
Pixels, Point, Render, ScrollWheelEvent, Styled, Subscription, Task, WeakEntity, actions,
anchored, deferred, div,
};
@@ -55,7 +55,7 @@ use workspace::{
CloseActiveItem, DraggedSelection, DraggedTab, NewCenterTerminal, NewTerminal, Pane,
ToolbarItemLocation, Workspace, WorkspaceId, delete_unloaded_items,
item::{
- BreadcrumbText, Item, ItemEvent, SerializableItem, TabContentParams, TabTooltipContent,
+ HighlightedText, Item, ItemEvent, SerializableItem, TabContentParams, TabTooltipContent,
},
register_serializable_item,
searchable::{
@@ -1655,12 +1655,14 @@ impl Item for TerminalView {
}
}
- fn breadcrumbs(&self, cx: &App) -> Option<Vec<BreadcrumbText>> {
- Some(vec![BreadcrumbText {
- text: self.terminal().read(cx).breadcrumb_text.clone(),
- highlights: None,
- font: None,
- }])
+ fn breadcrumbs(&self, cx: &App) -> Option<(Vec<HighlightedText>, Option<Font>)> {
+ Some((
+ vec![HighlightedText {
+ text: self.terminal().read(cx).breadcrumb_text.clone().into(),
+ highlights: vec![],
+ }],
+ None,
+ ))
}
fn added_to_workspace(
@@ -12,10 +12,11 @@ use client::{Client, proto};
use futures::{StreamExt, channel::mpsc};
use gpui::{
Action, AnyElement, AnyEntity, AnyView, App, AppContext, Context, Entity, EntityId,
- EventEmitter, FocusHandle, Focusable, Font, HighlightStyle, Pixels, Point, Render,
- SharedString, Task, WeakEntity, Window,
+ EventEmitter, FocusHandle, Focusable, Font, Pixels, Point, Render, SharedString, Task,
+ WeakEntity, Window,
};
use language::Capability;
+pub use language::HighlightedText;
use project::{Project, ProjectEntryId, ProjectPath};
pub use settings::{
ActivateOnClose, ClosePosition, RegisterSetting, Settings, SettingsLocation, ShowCloseButton,
@@ -25,7 +26,6 @@ use smallvec::SmallVec;
use std::{
any::{Any, TypeId},
cell::RefCell,
- ops::Range,
path::Path,
rc::Rc,
sync::Arc,
@@ -124,14 +124,6 @@ pub enum ItemEvent {
Edit,
}
-// TODO: Combine this with existing HighlightedText struct?
-#[derive(Debug)]
-pub struct BreadcrumbText {
- pub text: String,
- pub highlights: Option<Vec<(Range<usize>, HighlightStyle)>>,
- pub font: Option<Font>,
-}
-
#[derive(Clone, Copy, Default, Debug)]
pub struct TabContentParams {
pub detail: Option<usize>,
@@ -329,7 +321,7 @@ pub trait Item: Focusable + EventEmitter<Self::Event> + Render + Sized {
ToolbarItemLocation::Hidden
}
- fn breadcrumbs(&self, _cx: &App) -> Option<Vec<BreadcrumbText>> {
+ fn breadcrumbs(&self, _cx: &App) -> Option<(Vec<HighlightedText>, Option<Font>)> {
None
}
@@ -548,7 +540,7 @@ pub trait ItemHandle: 'static + Send {
) -> gpui::Subscription;
fn to_searchable_item_handle(&self, cx: &App) -> Option<Box<dyn SearchableItemHandle>>;
fn breadcrumb_location(&self, cx: &App) -> ToolbarItemLocation;
- fn breadcrumbs(&self, cx: &App) -> Option<Vec<BreadcrumbText>>;
+ fn breadcrumbs(&self, cx: &App) -> Option<(Vec<HighlightedText>, Option<Font>)>;
fn breadcrumb_prefix(&self, window: &mut Window, cx: &mut App) -> Option<gpui::AnyElement>;
fn show_toolbar(&self, cx: &App) -> bool;
fn pixel_position_of_cursor(&self, cx: &App) -> Option<Point<Pixels>>;
@@ -1090,7 +1082,7 @@ impl<T: Item> ItemHandle for Entity<T> {
self.read(cx).breadcrumb_location(cx)
}
- fn breadcrumbs(&self, cx: &App) -> Option<Vec<BreadcrumbText>> {
+ fn breadcrumbs(&self, cx: &App) -> Option<(Vec<HighlightedText>, Option<Font>)> {
self.read(cx).breadcrumbs(cx)
}