-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
assistant2: Allow removing individual context (#21868)
This PR adds the ability to remove individual pieces of context from the message editor: <img width="1159" alt="Screenshot 2024-12-11 at 12 38 45 PM" src="https://github.com/user-attachments/assets/77d04272-f667-4ebb-a567-84b382afef3d" /> Release Notes: - N/A
- Loading branch information
1 parent
124e63d
commit b3ffbea
Showing
3 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,49 @@ | ||
use ui::prelude::*; | ||
use std::rc::Rc; | ||
|
||
use gpui::ClickEvent; | ||
use ui::{prelude::*, IconButtonShape}; | ||
|
||
use crate::context::Context; | ||
|
||
#[derive(IntoElement)] | ||
pub struct ContextPill { | ||
context: Context, | ||
on_remove: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext)>>, | ||
} | ||
|
||
impl ContextPill { | ||
pub fn new(context: Context) -> Self { | ||
Self { context } | ||
Self { | ||
context, | ||
on_remove: None, | ||
} | ||
} | ||
|
||
pub fn on_remove(mut self, on_remove: Rc<dyn Fn(&ClickEvent, &mut WindowContext)>) -> Self { | ||
self.on_remove = Some(on_remove); | ||
self | ||
} | ||
} | ||
|
||
impl RenderOnce for ContextPill { | ||
fn render(self, cx: &mut WindowContext) -> impl IntoElement { | ||
div() | ||
h_flex() | ||
.gap_1() | ||
.px_1() | ||
.border_1() | ||
.border_color(cx.theme().colors().border) | ||
.rounded_md() | ||
.child(Label::new(self.context.name.clone()).size(LabelSize::Small)) | ||
.when_some(self.on_remove, |parent, on_remove| { | ||
parent.child( | ||
IconButton::new("remove", IconName::Close) | ||
.shape(IconButtonShape::Square) | ||
.icon_size(IconSize::XSmall) | ||
.on_click({ | ||
let on_remove = on_remove.clone(); | ||
move |event, cx| on_remove(event, cx) | ||
}), | ||
) | ||
}) | ||
} | ||
} |