Show quote selection button

Antonio Scandurra created

Change summary

assets/icons/quote_15.svg         |  0 
crates/ai/src/assistant.rs        | 29 +++++++++++++++++++++++++++++
crates/theme/src/theme.rs         |  1 +
styles/src/styleTree/assistant.ts | 15 ++++++++++++++-
4 files changed, 44 insertions(+), 1 deletion(-)

Detailed changes

crates/ai/src/assistant.rs 🔗

@@ -111,6 +111,7 @@ pub enum AssistantPanelEvent {
 }
 
 pub struct AssistantPanel {
+    workspace: WeakViewHandle<Workspace>,
     width: Option<f32>,
     height: Option<f32>,
     active_editor_index: Option<usize>,
@@ -143,6 +144,7 @@ impl AssistantPanel {
                 .unwrap_or_default();
 
             // TODO: deserialize state.
+            let workspace_handle = workspace.clone();
             workspace.update(&mut cx, |workspace, cx| {
                 cx.add_view::<Self, _>(|cx| {
                     const CONVERSATION_WATCH_DURATION: Duration = Duration::from_millis(100);
@@ -171,6 +173,7 @@ impl AssistantPanel {
                         toolbar
                     });
                     let mut this = Self {
+                        workspace: workspace_handle,
                         active_editor_index: Default::default(),
                         prev_active_editor_index: Default::default(),
                         editors: Default::default(),
@@ -364,6 +367,7 @@ impl AssistantPanel {
         if self.active_editor().is_some() {
             vec![
                 Self::render_split_button(&style.split_button, cx).into_any(),
+                Self::render_quote_button(&style.quote_button, cx).into_any(),
                 Self::render_assist_button(&style.assist_button, cx).into_any(),
             ]
         } else {
@@ -413,6 +417,31 @@ impl AssistantPanel {
             )
     }
 
+    fn render_quote_button(style: &IconStyle, cx: &mut ViewContext<Self>) -> impl Element<Self> {
+        let tooltip_style = theme::current(cx).tooltip.clone();
+        Svg::for_style(style.icon.clone())
+            .contained()
+            .with_style(style.container)
+            .mouse::<QuoteSelection>(0)
+            .with_cursor_style(CursorStyle::PointingHand)
+            .on_click(MouseButton::Left, |_, this: &mut Self, cx| {
+                if let Some(workspace) = this.workspace.upgrade(cx) {
+                    cx.window_context().defer(move |cx| {
+                        workspace.update(cx, |workspace, cx| {
+                            ConversationEditor::quote_selection(workspace, &Default::default(), cx)
+                        });
+                    });
+                }
+            })
+            .with_tooltip::<QuoteSelection>(
+                1,
+                "Assist".into(),
+                Some(Box::new(QuoteSelection)),
+                tooltip_style,
+                cx,
+            )
+    }
+
     fn render_plus_button(style: &IconStyle) -> impl Element<Self> {
         enum AddConversation {}
         Svg::for_style(style.icon.clone())

crates/theme/src/theme.rs 🔗

@@ -996,6 +996,7 @@ pub struct AssistantStyle {
     pub hamburger_button: IconStyle,
     pub split_button: IconStyle,
     pub assist_button: IconStyle,
+    pub quote_button: IconStyle,
     pub zoom_in_button: IconStyle,
     pub zoom_out_button: IconStyle,
     pub plus_button: IconStyle,

styles/src/styleTree/assistant.ts 🔗

@@ -41,6 +41,19 @@ export default function assistant(colorScheme: ColorScheme) {
                 margin: { left: 12 },
             }
         },
+        quoteButton: {
+            icon: {
+                color: text(layer, "sans", "default", { size: "sm" }).color,
+                asset: "icons/quote_15.svg",
+                dimensions: {
+                    width: 15,
+                    height: 15,
+                },
+            },
+            container: {
+                margin: { left: 12 },
+            }
+        },
         assistButton: {
             icon: {
                 color: text(layer, "sans", "default", { size: "sm" }).color,
@@ -51,7 +64,7 @@ export default function assistant(colorScheme: ColorScheme) {
                 },
             },
             container: {
-                margin: { left: 12, right: 12 },
+                margin: { left: 12, right: 24 },
             }
         },
         zoomInButton: {