From 9e49894ed61d1a610977518966183dbb8f580c12 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:00:43 -0300 Subject: [PATCH] assistant: Remove the selection action as an extra option (#20234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR should only be merged after https://github.com/zed-industries/zed/pull/19988. Once the selection action is added as a "proper" slash command, there's no need to have it duplicate on the "Add Context" menu anymore. 😄 Release Notes: - N/A --- crates/assistant/src/slash_command_picker.rs | 117 ++++++------------- 1 file changed, 37 insertions(+), 80 deletions(-) diff --git a/crates/assistant/src/slash_command_picker.rs b/crates/assistant/src/slash_command_picker.rs index 3d667d7f8284324a35e36c6b64991dc89da6660e..b376dd88814cd4cfc30d2cfab15e84f22dc5b13b 100644 --- a/crates/assistant/src/slash_command_picker.rs +++ b/crates/assistant/src/slash_command_picker.rs @@ -4,10 +4,9 @@ use assistant_slash_command::SlashCommandRegistry; use gpui::{AnyElement, DismissEvent, SharedString, Task, WeakView}; use picker::{Picker, PickerDelegate, PickerEditorPosition}; -use ui::{prelude::*, KeyBinding, ListItem, ListItemSpacing, PopoverMenu, PopoverTrigger}; +use ui::{prelude::*, ListItem, ListItemSpacing, PopoverMenu, PopoverTrigger}; use crate::assistant_panel::ContextEditor; -use crate::QuoteSelection; #[derive(IntoElement)] pub(super) struct SlashCommandSelector { @@ -32,7 +31,6 @@ enum SlashCommandEntry { renderer: fn(&mut WindowContext<'_>) -> AnyElement, on_confirm: fn(&mut WindowContext<'_>), }, - QuoteButton, } impl AsRef for SlashCommandEntry { @@ -40,7 +38,6 @@ impl AsRef for SlashCommandEntry { match self { SlashCommandEntry::Info(SlashCommandInfo { name, .. }) | SlashCommandEntry::Advert { name, .. } => name, - SlashCommandEntry::QuoteButton => "Quote Selection", } } } @@ -153,9 +150,6 @@ impl PickerDelegate for SlashCommandDelegate { }) .ok(); } - SlashCommandEntry::QuoteButton => { - cx.dispatch_action(Box::new(QuoteSelection)); - } SlashCommandEntry::Advert { on_confirm, .. } => { on_confirm(cx); } @@ -223,40 +217,6 @@ impl PickerDelegate for SlashCommandDelegate { ), ), ), - SlashCommandEntry::QuoteButton => { - let focus = cx.focus_handle(); - let key_binding = KeyBinding::for_action_in(&QuoteSelection, &focus, cx); - - Some( - ListItem::new(ix) - .inset(true) - .spacing(ListItemSpacing::Dense) - .selected(selected) - .child( - v_flex() - .child( - h_flex() - .gap_1p5() - .child(Icon::new(IconName::Quote).size(IconSize::XSmall)) - .child( - div().font_buffer(cx).child( - Label::new("selection").size(LabelSize::Small), - ), - ), - ) - .child( - h_flex() - .gap_1p5() - .child( - Label::new("Insert editor selection") - .color(Color::Muted) - .size(LabelSize::Small), - ) - .children(key_binding.map(|kb| kb.render(cx))), - ), - ), - ) - } SlashCommandEntry::Advert { renderer, .. } => Some( ListItem::new(ix) .inset(true) @@ -290,47 +250,44 @@ impl RenderOnce for SlashCommandSelector { icon: command.icon(), })) }) - .chain([ - SlashCommandEntry::Advert { - name: "create-your-command".into(), - renderer: |cx| { - v_flex() - .w_full() - .child( - h_flex() - .w_full() - .font_buffer(cx) - .items_center() - .justify_between() - .child( - h_flex() - .items_center() - .gap_1p5() - .child(Icon::new(IconName::Plus).size(IconSize::XSmall)) - .child( - div().font_buffer(cx).child( - Label::new("create-your-command") - .size(LabelSize::Small), - ), + .chain([SlashCommandEntry::Advert { + name: "create-your-command".into(), + renderer: |cx| { + v_flex() + .w_full() + .child( + h_flex() + .w_full() + .font_buffer(cx) + .items_center() + .justify_between() + .child( + h_flex() + .items_center() + .gap_1p5() + .child(Icon::new(IconName::Plus).size(IconSize::XSmall)) + .child( + div().font_buffer(cx).child( + Label::new("create-your-command") + .size(LabelSize::Small), ), - ) - .child( - Icon::new(IconName::ArrowUpRight) - .size(IconSize::XSmall) - .color(Color::Muted), - ), - ) - .child( - Label::new("Create your custom command") - .size(LabelSize::Small) - .color(Color::Muted), - ) - .into_any_element() - }, - on_confirm: |cx| cx.open_url("https://zed.dev/docs/extensions/slash-commands"), + ), + ) + .child( + Icon::new(IconName::ArrowUpRight) + .size(IconSize::XSmall) + .color(Color::Muted), + ), + ) + .child( + Label::new("Create your custom command") + .size(LabelSize::Small) + .color(Color::Muted), + ) + .into_any_element() }, - SlashCommandEntry::QuoteButton, - ]) + on_confirm: |cx| cx.open_url("https://zed.dev/docs/extensions/slash-commands"), + }]) .collect::>(); let delegate = SlashCommandDelegate {