From f5679f98d6bd677939e8a6650db7132a890948b2 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Fri, 1 Dec 2023 14:52:17 -0500 Subject: [PATCH 1/9] Update diagnostics style --- crates/diagnostics2/src/diagnostics.rs | 72 ++++++++++++++++++-------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/crates/diagnostics2/src/diagnostics.rs b/crates/diagnostics2/src/diagnostics.rs index 0a0f4da893..dd01f90b9f 100644 --- a/crates/diagnostics2/src/diagnostics.rs +++ b/crates/diagnostics2/src/diagnostics.rs @@ -774,24 +774,39 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock { Arc::new(move |_| { h_stack() .id("diagnostic header") - .gap_3() - .bg(gpui::red()) - .map(|stack| { - let icon = if diagnostic.severity == DiagnosticSeverity::ERROR { - IconElement::new(Icon::XCircle).color(Color::Error) - } else { - IconElement::new(Icon::ExclamationTriangle).color(Color::Warning) - }; - - stack.child(div().pl_8().child(icon)) - }) - .when_some(diagnostic.source.as_ref(), |stack, source| { - stack.child(Label::new(format!("{source}:")).color(Color::Accent)) - }) - .child(HighlightedLabel::new(message.clone(), highlights.clone())) - .when_some(diagnostic.code.as_ref(), |stack, code| { - stack.child(Label::new(code.clone())) - }) + .py_2() + .pl_10() + .pr_5() + .w_full() + .justify_between() + .gap_2() + .child( + h_stack() + .gap_3() + .map(|stack| { + let icon = if diagnostic.severity == DiagnosticSeverity::ERROR { + IconElement::new(Icon::XCircle).color(Color::Error) + } else { + IconElement::new(Icon::ExclamationTriangle).color(Color::Warning) + }; + stack.child(icon) + }) + .child( + h_stack() + .gap_1() + .child(HighlightedLabel::new(message.clone(), highlights.clone())) + .when_some(diagnostic.code.as_ref(), |stack, code| { + stack.child(Label::new(format!("({code})")).color(Color::Muted)) + }), + ), + ) + .child( + h_stack() + .gap_1() + .when_some(diagnostic.source.as_ref(), |stack, source| { + stack.child(Label::new(format!("{source}")).color(Color::Muted)) + }), + ) .into_any_element() }) } @@ -802,11 +817,22 @@ pub(crate) fn render_summary(summary: &DiagnosticSummary) -> AnyElement { label.into_any_element() } else { h_stack() - .bg(gpui::red()) - .child(IconElement::new(Icon::XCircle)) - .child(Label::new(summary.error_count.to_string())) - .child(IconElement::new(Icon::ExclamationTriangle)) - .child(Label::new(summary.warning_count.to_string())) + .gap_1() + .when(summary.error_count > 0, |then| { + then.child( + h_stack() + .gap_1() + .child(IconElement::new(Icon::XCircle).color(Color::Error)) + .child(Label::new(summary.error_count.to_string())), + ) + }) + .when(summary.warning_count > 0, |then| { + then.child( + h_stack() + .child(IconElement::new(Icon::ExclamationTriangle).color(Color::Warning)) + .child(Label::new(summary.warning_count.to_string())), + ) + }) .into_any_element() } } From 89aa6a372636baa1e7b8f1cd94f3d2004c47ed4b Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Fri, 1 Dec 2023 15:30:01 -0500 Subject: [PATCH 2/9] Re-add diagnostic headers --- assets/icons/copy.svg | 1 + crates/editor2/src/editor.rs | 32 +++++++++++++----- crates/editor2/src/element.rs | 55 +++++++++++++++++++++++-------- crates/ui2/src/components/icon.rs | 2 ++ 4 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 assets/icons/copy.svg diff --git a/assets/icons/copy.svg b/assets/icons/copy.svg new file mode 100644 index 0000000000..8b755e8063 --- /dev/null +++ b/assets/icons/copy.svg @@ -0,0 +1 @@ + diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index c7141fe587..9498895e71 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) -> Rend let 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 this v_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) + .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)), + ) })) - .cursor_pointer() - .on_click(cx.listener(move |_, _, cx| { - cx.write_to_clipboard(ClipboardItem::new(message.clone())); - })) - .tooltip(|cx| Tooltip::text("Copy diagnostic message", cx)) .into_any_element() }) } diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index 3abe5a37f9..c82586c5ae 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.rs index 12b3e57792..70d7a047c0 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", From c07455efa7da608a7c1ec28162ca975fded43223 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Fri, 1 Dec 2023 15:53:17 -0500 Subject: [PATCH 3/9] Update path header style Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- crates/editor2/src/element.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index c82586c5ae..95f6e99589 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -51,7 +51,9 @@ use std::{ }; use sum_tree::Bias; use theme::{ActiveTheme, PlayerColor}; -use ui::{h_stack, Disclosure, IconButton, IconSize, Label, Tooltip}; +use ui::{ + h_stack, ButtonLike, ButtonStyle, Disclosure, IconButton, IconElement, IconSize, Label, Tooltip, +}; use ui::{prelude::*, Icon}; use util::ResultExt; use workspace::item::Item; @@ -2235,6 +2237,7 @@ impl EditorElement { let jump_position = language::ToPoint::to_point(&jump_anchor, buffer); IconButton::new(block_id, Icon::ArrowUpRight) + .style(ButtonStyle::Subtle) .on_click(cx.listener_for(&self.editor, move |editor, e, cx| { editor.jump(jump_path.clone(), jump_position, jump_anchor, cx); })) @@ -2253,8 +2256,11 @@ impl EditorElement { .map(|p| SharedString::from(p.to_string_lossy().to_string() + "/")); } - div().id("path header block").size_full().p_1p5().child( + let is_open = true; + + div().id("path header container").size_full().p_1p5().child( h_stack() + .id("path header block") .py_1p5() .pl_3() .pr_2() @@ -2266,15 +2272,23 @@ impl EditorElement { .justify_between() .cursor_pointer() .hover(|style| style.bg(cx.theme().colors().element_hover)) + .on_click(cx.listener(|_editor, _event, _cx| { + // TODO: Implement collapsing path headers + todo!("Clicking path header") + })) .child( h_stack() .gap_3() // TODO: Add open/close state and toggle action .child( - div() - .border() - .border_color(gpui::red()) - .child(Disclosure::new(true)), + div().border().border_color(gpui::red()).child( + ButtonLike::new("path-header-disclosure-control") + .style(ButtonStyle::Subtle) + .child(IconElement::new(match is_open { + true => Icon::ChevronDown, + false => Icon::ChevronRight, + })), + ), ) .child( h_stack() From 03ebf0a5a9ec81f47cb0a9e6c3abd9963c633181 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Fri, 1 Dec 2023 16:20:39 -0500 Subject: [PATCH 4/9] Implement FixedWidth for all button types [no-ci] Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- crates/ui2/src/components/button/button.rs | 14 +++++++++++++- crates/ui2/src/components/button/button_like.rs | 17 +++++++++++++++++ crates/ui2/src/components/button/icon_button.rs | 14 +++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/crates/ui2/src/components/button/button.rs b/crates/ui2/src/components/button/button.rs index ce26ee76a5..d80b4a7ebf 100644 --- a/crates/ui2/src/components/button/button.rs +++ b/crates/ui2/src/components/button/button.rs @@ -1,4 +1,4 @@ -use gpui::AnyView; +use gpui::{AnyView, DefiniteLength}; use crate::prelude::*; use crate::{ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Label, LineHeightStyle}; @@ -49,6 +49,18 @@ impl Clickable for Button { } } +impl FixedWidth for Button { + fn width(mut self, width: DefiniteLength) -> Self { + self.base = self.base.width(width); + self + } + + fn full_width(mut self) -> Self { + self.base = self.base.full_width(); + self + } +} + impl ButtonCommon for Button { fn id(&self) -> &ElementId { self.base.id() diff --git a/crates/ui2/src/components/button/button_like.rs b/crates/ui2/src/components/button/button_like.rs index 29864a895d..c527e25494 100644 --- a/crates/ui2/src/components/button/button_like.rs +++ b/crates/ui2/src/components/button/button_like.rs @@ -1,3 +1,4 @@ +use gpui::{relative, DefiniteLength}; use gpui::{rems, transparent_black, AnyElement, AnyView, ClickEvent, Div, Hsla, Rems, Stateful}; use smallvec::SmallVec; @@ -177,6 +178,7 @@ pub struct ButtonLike { pub(super) style: ButtonStyle, pub(super) disabled: bool, pub(super) selected: bool, + pub(super) width: Option, size: ButtonSize, tooltip: Option AnyView>>, on_click: Option>, @@ -190,6 +192,7 @@ impl ButtonLike { style: ButtonStyle::default(), disabled: false, selected: false, + width: None, size: ButtonSize::Default, tooltip: None, children: SmallVec::new(), @@ -219,6 +222,18 @@ impl Clickable for ButtonLike { } } +impl FixedWidth for ButtonLike { + fn width(mut self, width: DefiniteLength) -> Self { + self.width = Some(width); + self + } + + fn full_width(mut self) -> Self { + self.width = Some(relative(1.)); + self + } +} + impl ButtonCommon for ButtonLike { fn id(&self) -> &ElementId { &self.id @@ -252,7 +267,9 @@ impl RenderOnce for ButtonLike { fn render(self, cx: &mut WindowContext) -> Self::Rendered { h_stack() .id(self.id.clone()) + .flex_none() .h(self.size.height()) + .when_some(self.width, |this, width| this.w(width)) .rounded_md() .cursor_pointer() .gap_1() diff --git a/crates/ui2/src/components/button/icon_button.rs b/crates/ui2/src/components/button/icon_button.rs index a62832059d..ae6c9a4ec2 100644 --- a/crates/ui2/src/components/button/icon_button.rs +++ b/crates/ui2/src/components/button/icon_button.rs @@ -1,4 +1,4 @@ -use gpui::{Action, AnyView}; +use gpui::{Action, AnyView, DefiniteLength}; use crate::prelude::*; use crate::{ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Icon, IconElement, IconSize}; @@ -60,6 +60,18 @@ impl Clickable for IconButton { } } +impl FixedWidth for IconButton { + fn width(mut self, width: DefiniteLength) -> Self { + self.base = self.base.width(width); + self + } + + fn full_width(mut self) -> Self { + self.base = self.base.full_width(); + self + } +} + impl ButtonCommon for IconButton { fn id(&self) -> &ElementId { self.base.id() From 2bf48872b6409345345ea2a53810aff9bc438951 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Fri, 1 Dec 2023 16:53:09 -0500 Subject: [PATCH 5/9] Progress on diagnostic multibuffer Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- crates/editor2/src/element.rs | 67 ++++++++++++++++--- .../ui2/src/components/button/button_like.rs | 1 + crates/ui2/src/styled_ext.rs | 14 ++++ 3 files changed, 71 insertions(+), 11 deletions(-) diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index 95f6e99589..824b8c7df8 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -2225,7 +2225,8 @@ impl EditorElement { .as_ref() .map(|project| project.read(cx).visible_worktrees(cx).count() > 1) .unwrap_or_default(); - let jump_icon = project::File::from_dyn(buffer.file()).map(|file| { + + let jump_handler = project::File::from_dyn(buffer.file()).map(|file| { let jump_path = ProjectPath { worktree_id: file.worktree_id(cx), path: file.path.clone(), @@ -2236,12 +2237,11 @@ impl EditorElement { .map_or(range.context.start, |primary| primary.start); let jump_position = language::ToPoint::to_point(&jump_anchor, buffer); - IconButton::new(block_id, Icon::ArrowUpRight) - .style(ButtonStyle::Subtle) - .on_click(cx.listener_for(&self.editor, move |editor, e, cx| { - editor.jump(jump_path.clone(), jump_position, jump_anchor, cx); - })) - .tooltip(|cx| Tooltip::for_action("Jump to Buffer", &OpenExcerpts, cx)) + let jump_handler = cx.listener_for(&self.editor, move |editor, e, cx| { + editor.jump(jump_path.clone(), jump_position, jump_anchor, cx); + }); + + jump_handler }); let element = if *starts_new_buffer { @@ -2303,16 +2303,61 @@ impl EditorElement { }), ), ) - .children(jump_icon), // .p_x(gutter_padding) + .children(jump_handler.map(|jump_handler| { + IconButton::new(block_id, Icon::ArrowUpRight) + .style(ButtonStyle::Subtle) + .on_click(jump_handler) + .tooltip(|cx| { + Tooltip::for_action("Jump to Buffer", &OpenExcerpts, cx) + }) + })), // .p_x(gutter_padding) ) } else { let text_style = style.text.clone(); h_stack() .id("collapsed context") .size_full() - .bg(gpui::red()) - .child("⋯") - .children(jump_icon) // .p_x(gutter_padding) + .gap(gutter_padding) + .child( + h_stack() + .justify_end() + .flex_none() + .w(gutter_width - gutter_padding) + .h_full() + .text_buffer(cx) + .text_color(cx.theme().colors().editor_line_number) + .child("..."), + ) + .map(|this| { + if let Some(jump_handler) = jump_handler { + this.child( + ButtonLike::new("jump to collapsed context") + .style(ButtonStyle::Transparent) + .full_width() + .on_click(jump_handler) + .tooltip(|cx| { + Tooltip::for_action( + "Jump to Buffer", + &OpenExcerpts, + cx, + ) + }) + .child( + div() + .h_px() + .w_full() + .bg(cx.theme().colors().border_variant) + .group_hover("", |style| { + style.bg(cx.theme().colors().border) + }), + ), + ) + } else { + this.child(div().size_full().bg(gpui::green())) + } + }) + // .child("⋯") + // .children(jump_icon) // .p_x(gutter_padding) }; element.into_any() } diff --git a/crates/ui2/src/components/button/button_like.rs b/crates/ui2/src/components/button/button_like.rs index c527e25494..6af81cae77 100644 --- a/crates/ui2/src/components/button/button_like.rs +++ b/crates/ui2/src/components/button/button_like.rs @@ -267,6 +267,7 @@ impl RenderOnce for ButtonLike { fn render(self, cx: &mut WindowContext) -> Self::Rendered { h_stack() .id(self.id.clone()) + .group("") .flex_none() .h(self.size.height()) .when_some(self.width, |this, width| this.w(width)) diff --git a/crates/ui2/src/styled_ext.rs b/crates/ui2/src/styled_ext.rs index cb224fd0fe..e567830d6c 100644 --- a/crates/ui2/src/styled_ext.rs +++ b/crates/ui2/src/styled_ext.rs @@ -1,4 +1,6 @@ use gpui::{px, Styled, WindowContext}; +use settings::Settings; +use theme::ThemeSettings; use crate::prelude::*; use crate::{ElevationIndex, UITextSize}; @@ -60,6 +62,18 @@ pub trait StyledExt: Styled + Sized { self.text_size(size) } + /// The font size for buffer text. + /// + /// Retrieves the default font size, or the user's custom font size if set. + /// + /// This should only be used for text that is displayed in a buffer, + /// or other places that text needs to match the user's buffer font size. + fn text_buffer(self, cx: &mut WindowContext) -> Self { + let settings = ThemeSettings::get_global(cx); + + self.text_size(settings.buffer_font_size) + } + /// The [`Surface`](ui2::ElevationIndex::Surface) elevation level, located above the app background, is the standard level for all elements /// /// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()` From 4ee4e4e8d880d261ff2d085bf8ff474ecdbe9cf4 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Mon, 4 Dec 2023 11:41:31 -0500 Subject: [PATCH 6/9] =?UTF-8?q?Fix=20ci=20error=20=E2=80=93=20Copy=20to=20?= =?UTF-8?q?clipboard=20isn't=20implemented=20in=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- crates/editor2/src/editor.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 9498895e71..a4f19428fa 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -9695,7 +9695,8 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend 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: `cx.write_to_clipboard` is not implemented in tests. + // 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 this @@ -9718,7 +9719,8 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend IconButton::new(copy_id.clone(), Icon::Copy) // .color(Color::Muted) .size(ButtonSize::Compact) - .on_click(cx.listener(move |_, _, cx| write_to_clipboard)) + // TODO: `cx.write_to_clipboard` is not implemented in tests. + // .on_click(cx.listener(move |_, _, cx| write_to_clipboard)) .tooltip(|cx| Tooltip::text("Copy diagnostic message", cx)), ) })) From 23626aa902f5983a29737ab2d1bef6a80e078111 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Mon, 4 Dec 2023 11:50:26 -0500 Subject: [PATCH 7/9] Update diagnostic style Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- crates/editor2/src/editor.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index a4f19428fa..e985ff0ee5 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -100,7 +100,7 @@ use text::{OffsetUtf16, Rope}; use theme::{ ActiveTheme, DiagnosticStyle, PlayerColor, SyntaxTheme, Theme, ThemeColors, ThemeSettings, }; -use ui::{h_stack, v_stack, ButtonSize, HighlightedLabel, Icon, IconButton, Popover, Tooltip}; +use ui::{h_stack, v_stack, ButtonSize, HighlightedLabel, Icon, IconButton, Popover, Tooltip, ButtonStyle}; use ui::{prelude::*, IconSize}; use util::{post_inc, RangeExt, ResultExt, TryFutureExt}; use workspace::{ @@ -9706,22 +9706,26 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend .size_full() .bg(gpui::red()) .children(highlighted_lines.iter().map(|(line, highlights)| { + let group_id = cx.block_id.to_string(); + h_stack() - .items_start() + .group(group_id.clone()) .gap_2() - .elevation_2(cx) .absolute() .left(cx.anchor_x) .px_1p5() - .py_0p5() .child(HighlightedLabel::new(line.clone(), highlights.clone())) .child( + div() + .invisible() + .group_hover(group_id, |style| style.visible()).child( IconButton::new(copy_id.clone(), Icon::Copy) - // .color(Color::Muted) + .icon_color(Color::Muted) .size(ButtonSize::Compact) + .style(ButtonStyle::Transparent) // TODO: `cx.write_to_clipboard` is not implemented in tests. // .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() From e928ed44a02af1599c61ef0f05c69de931a25035 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Mon, 4 Dec 2023 11:53:46 -0500 Subject: [PATCH 8/9] Mark copy button as incomplete Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> --- crates/editor2/src/editor.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index e985ff0ee5..fd60564ff3 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -9717,6 +9717,8 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend .child(HighlightedLabel::new(line.clone(), highlights.clone())) .child( div() + .border() + .border_color(gpui::red()) .invisible() .group_hover(group_id, |style| style.visible()).child( IconButton::new(copy_id.clone(), Icon::Copy) From 26c797c3585810941ae1a8fbf2b8f2ba6381b8e2 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Mon, 4 Dec 2023 11:57:10 -0500 Subject: [PATCH 9/9] Format code --- crates/editor2/src/editor.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index cbe886018a..e9979a3ae2 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -100,7 +100,9 @@ use text::{OffsetUtf16, Rope}; use theme::{ ActiveTheme, DiagnosticStyle, PlayerColor, SyntaxTheme, Theme, ThemeColors, ThemeSettings, }; -use ui::{h_stack, v_stack, ButtonSize, HighlightedLabel, Icon, IconButton, Popover, Tooltip, ButtonStyle}; +use ui::{ + h_stack, v_stack, ButtonSize, ButtonStyle, HighlightedLabel, Icon, IconButton, Popover, Tooltip, +}; use ui::{prelude::*, IconSize}; use util::{post_inc, RangeExt, ResultExt, TryFutureExt}; use workspace::{ @@ -9715,14 +9717,16 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend .border() .border_color(gpui::red()) .invisible() - .group_hover(group_id, |style| style.visible()).child( - IconButton::new(copy_id.clone(), Icon::Copy) - .icon_color(Color::Muted) - .size(ButtonSize::Compact) - .style(ButtonStyle::Transparent) - // TODO: `cx.write_to_clipboard` is not implemented in tests. - // .on_click(cx.listener(move |_, _, cx| write_to_clipboard)) - .tooltip(|cx| Tooltip::text("Copy diagnostic message", cx))), + .group_hover(group_id, |style| style.visible()) + .child( + IconButton::new(copy_id.clone(), Icon::Copy) + .icon_color(Color::Muted) + .size(ButtonSize::Compact) + .style(ButtonStyle::Transparent) + // TODO: `cx.write_to_clipboard` is not implemented in tests. + // .on_click(cx.listener(move |_, _, cx| write_to_clipboard)) + .tooltip(|cx| Tooltip::text("Copy diagnostic message", cx)), + ), ) })) .into_any_element()