assistant: Remove the selection action as an extra option (#20234)

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
This commit is contained in:
Danilo Leal 2024-11-05 15:00:43 -03:00 committed by GitHub
parent 2364804f17
commit 9e49894ed6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,10 +4,9 @@ use assistant_slash_command::SlashCommandRegistry;
use gpui::{AnyElement, DismissEvent, SharedString, Task, WeakView}; use gpui::{AnyElement, DismissEvent, SharedString, Task, WeakView};
use picker::{Picker, PickerDelegate, PickerEditorPosition}; 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::assistant_panel::ContextEditor;
use crate::QuoteSelection;
#[derive(IntoElement)] #[derive(IntoElement)]
pub(super) struct SlashCommandSelector<T: PopoverTrigger> { pub(super) struct SlashCommandSelector<T: PopoverTrigger> {
@ -32,7 +31,6 @@ enum SlashCommandEntry {
renderer: fn(&mut WindowContext<'_>) -> AnyElement, renderer: fn(&mut WindowContext<'_>) -> AnyElement,
on_confirm: fn(&mut WindowContext<'_>), on_confirm: fn(&mut WindowContext<'_>),
}, },
QuoteButton,
} }
impl AsRef<str> for SlashCommandEntry { impl AsRef<str> for SlashCommandEntry {
@ -40,7 +38,6 @@ impl AsRef<str> for SlashCommandEntry {
match self { match self {
SlashCommandEntry::Info(SlashCommandInfo { name, .. }) SlashCommandEntry::Info(SlashCommandInfo { name, .. })
| SlashCommandEntry::Advert { name, .. } => name, | SlashCommandEntry::Advert { name, .. } => name,
SlashCommandEntry::QuoteButton => "Quote Selection",
} }
} }
} }
@ -153,9 +150,6 @@ impl PickerDelegate for SlashCommandDelegate {
}) })
.ok(); .ok();
} }
SlashCommandEntry::QuoteButton => {
cx.dispatch_action(Box::new(QuoteSelection));
}
SlashCommandEntry::Advert { on_confirm, .. } => { SlashCommandEntry::Advert { on_confirm, .. } => {
on_confirm(cx); 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( SlashCommandEntry::Advert { renderer, .. } => Some(
ListItem::new(ix) ListItem::new(ix)
.inset(true) .inset(true)
@ -290,47 +250,44 @@ impl<T: PopoverTrigger> RenderOnce for SlashCommandSelector<T> {
icon: command.icon(), icon: command.icon(),
})) }))
}) })
.chain([ .chain([SlashCommandEntry::Advert {
SlashCommandEntry::Advert { name: "create-your-command".into(),
name: "create-your-command".into(), renderer: |cx| {
renderer: |cx| { v_flex()
v_flex() .w_full()
.w_full() .child(
.child( h_flex()
h_flex() .w_full()
.w_full() .font_buffer(cx)
.font_buffer(cx) .items_center()
.items_center() .justify_between()
.justify_between() .child(
.child( h_flex()
h_flex() .items_center()
.items_center() .gap_1p5()
.gap_1p5() .child(Icon::new(IconName::Plus).size(IconSize::XSmall))
.child(Icon::new(IconName::Plus).size(IconSize::XSmall)) .child(
.child( div().font_buffer(cx).child(
div().font_buffer(cx).child( Label::new("create-your-command")
Label::new("create-your-command") .size(LabelSize::Small),
.size(LabelSize::Small),
),
), ),
) ),
.child( )
Icon::new(IconName::ArrowUpRight) .child(
.size(IconSize::XSmall) Icon::new(IconName::ArrowUpRight)
.color(Color::Muted), .size(IconSize::XSmall)
), .color(Color::Muted),
) ),
.child( )
Label::new("Create your custom command") .child(
.size(LabelSize::Small) Label::new("Create your custom command")
.color(Color::Muted), .size(LabelSize::Small)
) .color(Color::Muted),
.into_any_element() )
}, .into_any_element()
on_confirm: |cx| cx.open_url("https://zed.dev/docs/extensions/slash-commands"),
}, },
SlashCommandEntry::QuoteButton, on_confirm: |cx| cx.open_url("https://zed.dev/docs/extensions/slash-commands"),
]) }])
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let delegate = SlashCommandDelegate { let delegate = SlashCommandDelegate {