assistant: Add action footer and refine slash command popover (#16360)
- [x] Put the slash command popover on the footer - [x] Refine the popover (change it to a picker) - [x] Add more options dropdown on the assistant's toolbar - [x] Add quote selection button on the footer --- Release Notes: - N/A --------- Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Co-authored-by: Nate Butler <iamnbutler@gmail.com> Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This commit is contained in:
parent
23d56a1a84
commit
2180dbdb50
8 changed files with 402 additions and 89 deletions
|
@ -51,6 +51,15 @@ pub struct Picker<D: PickerDelegate> {
|
|||
is_modal: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq)]
|
||||
pub enum PickerEditorPosition {
|
||||
#[default]
|
||||
/// Render the editor at the start of the picker. Usually the top
|
||||
Start,
|
||||
/// Render the editor at the end of the picker. Usually the bottom
|
||||
End,
|
||||
}
|
||||
|
||||
pub trait PickerDelegate: Sized + 'static {
|
||||
type ListItem: IntoElement;
|
||||
|
||||
|
@ -103,8 +112,16 @@ pub trait PickerDelegate: Sized + 'static {
|
|||
None
|
||||
}
|
||||
|
||||
fn editor_position(&self) -> PickerEditorPosition {
|
||||
PickerEditorPosition::default()
|
||||
}
|
||||
|
||||
fn render_editor(&self, editor: &View<Editor>, _cx: &mut ViewContext<Picker<Self>>) -> Div {
|
||||
v_flex()
|
||||
.when(
|
||||
self.editor_position() == PickerEditorPosition::End,
|
||||
|this| this.child(Divider::horizontal()),
|
||||
)
|
||||
.child(
|
||||
h_flex()
|
||||
.overflow_hidden()
|
||||
|
@ -113,7 +130,10 @@ pub trait PickerDelegate: Sized + 'static {
|
|||
.px_3()
|
||||
.child(editor.clone()),
|
||||
)
|
||||
.child(Divider::horizontal())
|
||||
.when(
|
||||
self.editor_position() == PickerEditorPosition::Start,
|
||||
|this| this.child(Divider::horizontal()),
|
||||
)
|
||||
}
|
||||
|
||||
fn render_match(
|
||||
|
@ -555,6 +575,8 @@ impl<D: PickerDelegate> ModalView for Picker<D> {}
|
|||
|
||||
impl<D: PickerDelegate> Render for Picker<D> {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let editor_position = self.delegate.editor_position();
|
||||
|
||||
v_flex()
|
||||
.key_context("Picker")
|
||||
.size_full()
|
||||
|
@ -574,9 +596,15 @@ impl<D: PickerDelegate> Render for Picker<D> {
|
|||
.on_action(cx.listener(Self::secondary_confirm))
|
||||
.on_action(cx.listener(Self::confirm_completion))
|
||||
.on_action(cx.listener(Self::confirm_input))
|
||||
.child(match &self.head {
|
||||
Head::Editor(editor) => self.delegate.render_editor(&editor.clone(), cx),
|
||||
Head::Empty(empty_head) => div().child(empty_head.clone()),
|
||||
.children(match &self.head {
|
||||
Head::Editor(editor) => {
|
||||
if editor_position == PickerEditorPosition::Start {
|
||||
Some(self.delegate.render_editor(&editor.clone(), cx))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Head::Empty(empty_head) => Some(div().child(empty_head.clone())),
|
||||
})
|
||||
.when(self.delegate.match_count() > 0, |el| {
|
||||
el.child(
|
||||
|
@ -602,5 +630,15 @@ impl<D: PickerDelegate> Render for Picker<D> {
|
|||
)
|
||||
})
|
||||
.children(self.delegate.render_footer(cx))
|
||||
.children(match &self.head {
|
||||
Head::Editor(editor) => {
|
||||
if editor_position == PickerEditorPosition::End {
|
||||
Some(self.delegate.render_editor(&editor.clone(), cx))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Head::Empty(empty_head) => Some(div().child(empty_head.clone())),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue