From 667fc25766f62d2a45729cb8cb09f7889c990a0f Mon Sep 17 00:00:00 2001 From: Mikayla Date: Mon, 25 Sep 2023 11:31:02 -0700 Subject: [PATCH] Fix space and copy/paste when editing a channel --- assets/keymaps/default.json | 10 ++++++++-- crates/collab_ui/src/collab_panel.rs | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 8fbe87de2b..cdd8930b17 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -588,14 +588,20 @@ } }, { - "context": "CollabPanel", + "context": "CollabPanel && not_editing", "bindings": { "ctrl-backspace": "collab_panel::Remove", "space": "menu::Confirm" } }, { - "context": "CollabPanel > Editor", + "context": "(CollabPanel && editing) > Editor", + "bindings": { + "space": "collab_panel::InsertSpace" + } + }, + { + "context": "(CollabPanel && not_editing) > Editor", "bindings": { "cmd-c": "collab_panel::StartLinkChannel", "cmd-x": "collab_panel::StartMoveChannel", diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs index 6013ea4907..311978578c 100644 --- a/crates/collab_ui/src/collab_panel.rs +++ b/crates/collab_ui/src/collab_panel.rs @@ -136,6 +136,7 @@ actions!( StartMoveChannel, StartLinkChannel, MoveOrLinkToSelected, + InsertSpace, ] ); @@ -184,6 +185,7 @@ pub fn init(cx: &mut AppContext) { cx.add_action(CollabPanel::select_next); cx.add_action(CollabPanel::select_prev); cx.add_action(CollabPanel::confirm); + cx.add_action(CollabPanel::insert_space); cx.add_action(CollabPanel::remove); cx.add_action(CollabPanel::remove_selected_channel); cx.add_action(CollabPanel::show_inline_context_menu); @@ -2518,6 +2520,14 @@ impl CollabPanel { } } + fn insert_space(&mut self, _: &InsertSpace, cx: &mut ViewContext) { + if self.channel_editing_state.is_some() { + self.channel_name_editor.update(cx, |editor, cx| { + editor.insert(" ", cx); + }); + } + } + fn confirm_channel_edit(&mut self, cx: &mut ViewContext) -> bool { if let Some(editing_state) = &mut self.channel_editing_state { match editing_state { @@ -3054,6 +3064,19 @@ impl View for CollabPanel { .on_click(MouseButton::Left, |_, _, cx| cx.focus_self()) .into_any_named("collab panel") } + + fn update_keymap_context( + &self, + keymap: &mut gpui::keymap_matcher::KeymapContext, + _: &AppContext, + ) { + Self::reset_to_default_keymap_context(keymap); + if self.channel_editing_state.is_some() { + keymap.add_identifier("editing"); + } else { + keymap.add_identifier("not_editing"); + } + } } impl Panel for CollabPanel {