From ef8cab65b039d7bf8c1c8005302c394cbf8fdffe Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner <53836821+bennetbo@users.noreply.github.com> Date: Wed, 7 Feb 2024 21:14:36 +0100 Subject: [PATCH] allow closing reply to preview with action Co-Authored-By: Remco Smits <62463826+RemcoSmitsDev@users.noreply.github.com> --- assets/keymaps/default.json | 6 ++++++ crates/collab_ui/src/chat_panel.rs | 23 ++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 06358dab22..6e2b96b338 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -565,6 +565,12 @@ "tab": "channel_modal::ToggleMode" } }, + { + "context": "ChatPanel > MessageEditor", + "bindings": { + "escape": "chat_panel::CloseReplyPreview" + } + }, { "context": "Terminal", "bindings": { diff --git a/crates/collab_ui/src/chat_panel.rs b/crates/collab_ui/src/chat_panel.rs index 9a751335fa..999f02f2e0 100644 --- a/crates/collab_ui/src/chat_panel.rs +++ b/crates/collab_ui/src/chat_panel.rs @@ -70,7 +70,7 @@ struct SerializedChatPanel { width: Option, } -actions!(chat_panel, [ToggleFocus]); +actions!(chat_panel, [ToggleFocus, CloseReplyPreview]); impl ChatPanel { pub fn new(workspace: &mut Workspace, cx: &mut ViewContext) -> View { @@ -719,6 +719,11 @@ impl ChatPanel { Ok(()) }) } + + fn close_reply_preview(&mut self, _: &CloseReplyPreview, cx: &mut ViewContext) { + self.message_editor + .update(cx, |editor, _| editor.clear_reply_to_message_id()); + } } 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(); v_flex() + .key_context("ChatPanel") .track_focus(&self.focus_handle) .full() .on_action(cx.listener(Self::send)) @@ -810,10 +816,15 @@ impl Render for ChatPanel { .child( IconButton::new("close-reply-preview", IconName::Close) .shape(ui::IconButtonShape::Square) - .on_click(cx.listener(move |this, _, cx| { - this.message_editor.update(cx, |editor, _| { - editor.clear_reply_to_message_id() - }); + .tooltip(|cx| { + Tooltip::for_action( + "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( Some( h_flex() + .key_context("MessageEditor") + .on_action(cx.listener(ChatPanel::close_reply_preview)) .when( !self.is_scrolled_to_bottom && reply_to_message_id.is_none(), |el| el.border_t_1().border_color(cx.theme().colors().border),