allow closing reply to preview with action

Co-Authored-By: Remco Smits <62463826+RemcoSmitsDev@users.noreply.github.com>
This commit is contained in:
Bennet Bo Fenner 2024-02-07 21:14:36 +01:00
parent 6b598a07d9
commit ef8cab65b0
2 changed files with 24 additions and 5 deletions

View file

@ -565,6 +565,12 @@
"tab": "channel_modal::ToggleMode" "tab": "channel_modal::ToggleMode"
} }
}, },
{
"context": "ChatPanel > MessageEditor",
"bindings": {
"escape": "chat_panel::CloseReplyPreview"
}
},
{ {
"context": "Terminal", "context": "Terminal",
"bindings": { "bindings": {

View file

@ -70,7 +70,7 @@ struct SerializedChatPanel {
width: Option<Pixels>, width: Option<Pixels>,
} }
actions!(chat_panel, [ToggleFocus]); actions!(chat_panel, [ToggleFocus, CloseReplyPreview]);
impl ChatPanel { impl ChatPanel {
pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> { pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
@ -719,6 +719,11 @@ impl ChatPanel {
Ok(()) Ok(())
}) })
} }
fn close_reply_preview(&mut self, _: &CloseReplyPreview, cx: &mut ViewContext<Self>) {
self.message_editor
.update(cx, |editor, _| editor.clear_reply_to_message_id());
}
} }
impl Render for ChatPanel { impl Render for ChatPanel {
@ -726,6 +731,7 @@ impl Render for ChatPanel {
let reply_to_message_id = self.message_editor.read(cx).reply_to_message_id(); let reply_to_message_id = self.message_editor.read(cx).reply_to_message_id();
v_flex() v_flex()
.key_context("ChatPanel")
.track_focus(&self.focus_handle) .track_focus(&self.focus_handle)
.full() .full()
.on_action(cx.listener(Self::send)) .on_action(cx.listener(Self::send))
@ -810,10 +816,15 @@ impl Render for ChatPanel {
.child( .child(
IconButton::new("close-reply-preview", IconName::Close) IconButton::new("close-reply-preview", IconName::Close)
.shape(ui::IconButtonShape::Square) .shape(ui::IconButtonShape::Square)
.on_click(cx.listener(move |this, _, cx| { .tooltip(|cx| {
this.message_editor.update(cx, |editor, _| { Tooltip::for_action(
editor.clear_reply_to_message_id() "Close reply preview",
}); &CloseReplyPreview,
cx,
)
})
.on_click(cx.listener(move |_, _, cx| {
cx.dispatch_action(CloseReplyPreview.boxed_clone())
})), })),
), ),
) )
@ -822,6 +833,8 @@ impl Render for ChatPanel {
.children( .children(
Some( Some(
h_flex() h_flex()
.key_context("MessageEditor")
.on_action(cx.listener(ChatPanel::close_reply_preview))
.when( .when(
!self.is_scrolled_to_bottom && reply_to_message_id.is_none(), !self.is_scrolled_to_bottom && reply_to_message_id.is_none(),
|el| el.border_t_1().border_color(cx.theme().colors().border), |el| el.border_t_1().border_color(cx.theme().colors().border),