Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Re-add diagnostic headers
Nate Butler89aa6a372636
diff --git a/assets/icons/copy.svg b/assets/icons/copy.svgnew file mode 100644index 00000000000..8b755e80639--- /dev/null+++ b/assets/icons/copy.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rsindex c7141fe5879..9498895e714 100644--- a/crates/editor2/src/editor.rs+++ b/crates/editor2/src/editor.rs@@ -100,8 +100,8 @@ use text::{OffsetUtf16, Rope};use theme::{ActiveTheme, DiagnosticStyle, PlayerColor, SyntaxTheme, Theme, ThemeColors, ThemeSettings,};-use ui::prelude::*;-use ui::{h_stack, v_stack, HighlightedLabel, IconButton, Popover, Tooltip};+use ui::{h_stack, v_stack, ButtonSize, HighlightedLabel, Icon, IconButton, Popover, Tooltip};+use ui::{prelude::*, IconSize};use util::{post_inc, RangeExt, ResultExt, TryFutureExt};use workspace::{item::{ItemEvent, ItemHandle},@@ -9694,20 +9694,34 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rendlet message = diagnostic.message;Arc::new(move |cx: &mut BlockContext| {let message = message.clone();+ let copy_id: SharedString = format!("copy-{}", cx.block_id.clone()).to_string().into();+ let write_to_clipboard = cx.write_to_clipboard(ClipboardItem::new(message.clone()));++ // TODO: Nate: We should tint the background of the block with the severity color+ // We need to extend the theme before we can do thisv_stack().id(cx.block_id)+ .relative().size_full().bg(gpui::red()).children(highlighted_lines.iter().map(|(line, highlights)| {- div()+ h_stack()+ .items_start()+ .gap_2()+ .elevation_2(cx)+ .absolute()+ .left(cx.anchor_x)+ .px_1p5()+ .py_0p5().child(HighlightedLabel::new(line.clone(), highlights.clone()))- .ml(cx.anchor_x)- }))- .cursor_pointer()- .on_click(cx.listener(move |_, _, cx| {- cx.write_to_clipboard(ClipboardItem::new(message.clone()));+ .child(+ IconButton::new(copy_id.clone(), Icon::Copy)+ // .color(Color::Muted)+ .size(ButtonSize::Compact)+ .on_click(cx.listener(move |_, _, cx| write_to_clipboard))+ .tooltip(|cx| Tooltip::text("Copy diagnostic message", cx)),+ )}))- .tooltip(|cx| Tooltip::text("Copy diagnostic message", cx)).into_any_element()})}diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rsindex 3abe5a37f97..c82586c5ae1 100644--- a/crates/editor2/src/element.rs+++ b/crates/editor2/src/element.rs@@ -51,8 +51,8 @@ use std::{};use sum_tree::Bias;use theme::{ActiveTheme, PlayerColor};-use ui::prelude::*;-use ui::{h_stack, IconButton, Tooltip};+use ui::{h_stack, Disclosure, IconButton, IconSize, Label, Tooltip};+use ui::{prelude::*, Icon};use util::ResultExt;use workspace::item::Item;@@ -2234,7 +2234,7 @@ impl EditorElement {.map_or(range.context.start, |primary| primary.start);let jump_position = language::ToPoint::to_point(&jump_anchor, buffer);- IconButton::new(block_id, ui::Icon::ArrowUpRight)+ IconButton::new(block_id, Icon::ArrowUpRight).on_click(cx.listener_for(&self.editor, move |editor, e, cx| {editor.jump(jump_path.clone(), jump_position, jump_anchor, cx);}))@@ -2253,17 +2253,44 @@ impl EditorElement {.map(|p| SharedString::from(p.to_string_lossy().to_string() + "/"));}- h_stack()- .id("path header block")- .size_full()- .bg(gpui::red())- .child(- filename- .map(SharedString::from)- .unwrap_or_else(|| "untitled".into()),- )- .children(parent_path)- .children(jump_icon) // .p_x(gutter_padding)+ div().id("path header block").size_full().p_1p5().child(+ h_stack()+ .py_1p5()+ .pl_3()+ .pr_2()+ .rounded_lg()+ .shadow_md()+ .border()+ .border_color(cx.theme().colors().border)+ .bg(cx.theme().colors().editor_subheader_background)+ .justify_between()+ .cursor_pointer()+ .hover(|style| style.bg(cx.theme().colors().element_hover))+ .child(+ h_stack()+ .gap_3()+ // TODO: Add open/close state and toggle action+ .child(+ div()+ .border()+ .border_color(gpui::red())+ .child(Disclosure::new(true)),+ )+ .child(+ h_stack()+ .gap_2()+ .child(Label::new(+ filename+ .map(SharedString::from)+ .unwrap_or_else(|| "untitled".into()),+ ))+ .when_some(parent_path, |then, path| {+ then.child(Label::new(path).color(Color::Muted))+ }),+ ),+ )+ .children(jump_icon), // .p_x(gutter_padding)+ )} else {let text_style = style.text.clone();h_stack()diff --git a/crates/ui2/src/components/icon.rs b/crates/ui2/src/components/icon.rsindex 12b3e577926..70d7a047c00 100644--- a/crates/ui2/src/components/icon.rs+++ b/crates/ui2/src/components/icon.rs@@ -27,6 +27,7 @@ pub enum Icon {Bolt,CaseSensitive,Check,+ Copy,ChevronDown,ChevronLeft,ChevronRight,@@ -99,6 +100,7 @@ impl Icon {Icon::Bolt => "icons/bolt.svg",Icon::CaseSensitive => "icons/case_insensitive.svg",Icon::Check => "icons/check.svg",+ Icon::Copy => "icons/copy.svg",Icon::ChevronDown => "icons/chevron_down.svg",Icon::ChevronLeft => "icons/chevron_left.svg",Icon::ChevronRight => "icons/chevron_right.svg",