From 490b65b55f7691f1e19755bdd8e8a76e05835378 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 21 Apr 2022 15:24:05 -0700 Subject: [PATCH] Reuse Confirm action in chat panel, go-to-line, and project search --- assets/keymaps/default.json | 33 ++++++----------------------- crates/chat_panel/src/chat_panel.rs | 5 +++-- crates/go_to_line/src/go_to_line.rs | 12 +++++++++-- crates/search/src/project_search.rs | 8 ++++--- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index eb49ff6d24..6eaff19f89 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -1,7 +1,6 @@ [ // Standard macOS bindings { - "context": "menu", "bindings": { "up": "menu::SelectPrev", "ctrl-p": "menu::SelectPrev", @@ -11,11 +10,7 @@ "cmd-down": "menu::SelectLast", "enter": "menu::Confirm", "escape": "menu::Cancel", - "ctrl-c": "menu::Cancel" - } - }, - { - "bindings": { + "ctrl-c": "menu::Cancel", "shift-cmd-{": "pane::ActivatePrevItem", "shift-cmd-}": "pane::ActivateNextItem", "cmd-w": "pane::CloseActiveItem", @@ -287,6 +282,12 @@ "cmd-f10": "editor::RestartLanguageServer" } }, + { + "context": "ProjectSearchBar", + "bindings": { + "cmd-enter": "project_search::SearchInNew" + } + }, { "context": "Workspace", "bindings": { @@ -317,13 +318,6 @@ }, // Bindings that should be unified with other bindings // for more general actions - { - "context": "ProjectSearchBar", - "bindings": { - "enter": "project_search::Search", - "cmd-enter": "project_search::SearchInNew" - } - }, { "context": "Editor && renaming", "bindings": { @@ -342,18 +336,5 @@ "bindings": { "enter": "editor::ConfirmCodeAction" } - }, - { - "context": "GoToLine", - "bindings": { - "escape": "go_to_line::Toggle", - "enter": "go_to_line::Confirm" - } - }, - { - "context": "ChatPanel", - "bindings": { - "enter": "chat_panel::Send" - } } ] \ No newline at end of file diff --git a/crates/chat_panel/src/chat_panel.rs b/crates/chat_panel/src/chat_panel.rs index 187c0139db..415ff6187e 100644 --- a/crates/chat_panel/src/chat_panel.rs +++ b/crates/chat_panel/src/chat_panel.rs @@ -16,6 +16,7 @@ use settings::{Settings, SoftWrap}; use std::sync::Arc; use time::{OffsetDateTime, UtcOffset}; use util::{ResultExt, TryFutureExt}; +use workspace::menu::Confirm; const MESSAGE_LOADING_THRESHOLD: usize = 50; @@ -32,7 +33,7 @@ pub struct ChatPanel { pub enum Event {} -actions!(chat_panel, [Send, LoadMoreMessages]); +actions!(chat_panel, [LoadMoreMessages]); pub fn init(cx: &mut MutableAppContext) { cx.add_action(ChatPanel::send); @@ -345,7 +346,7 @@ impl ChatPanel { .boxed() } - fn send(&mut self, _: &Send, cx: &mut ViewContext) { + fn send(&mut self, _: &Confirm, cx: &mut ViewContext) { if let Some((channel, _)) = self.active_channel.as_ref() { let body = self.input_editor.update(cx, |editor, cx| { let body = editor.text(cx); diff --git a/crates/go_to_line/src/go_to_line.rs b/crates/go_to_line/src/go_to_line.rs index 16b633ad72..7fa68a7675 100644 --- a/crates/go_to_line/src/go_to_line.rs +++ b/crates/go_to_line/src/go_to_line.rs @@ -5,13 +5,17 @@ use gpui::{ }; use settings::Settings; use text::{Bias, Point}; -use workspace::Workspace; +use workspace::{ + menu::{Cancel, Confirm}, + Workspace, +}; -actions!(go_to_line, [Toggle, Confirm]); +actions!(go_to_line, [Toggle]); pub fn init(cx: &mut MutableAppContext) { cx.add_action(GoToLine::toggle); cx.add_action(GoToLine::confirm); + cx.add_action(GoToLine::cancel); } pub struct GoToLine { @@ -66,6 +70,10 @@ impl GoToLine { } } + fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext) { + cx.emit(Event::Dismissed); + } + fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext) { self.prev_scroll_position.take(); self.active_editor.update(cx, |active_editor, cx| { diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 1028d7f77e..bb35b2ebdc 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -17,9 +17,11 @@ use std::{ path::PathBuf, }; use util::ResultExt as _; -use workspace::{Item, ItemNavHistory, Pane, ToolbarItemLocation, ToolbarItemView, Workspace}; +use workspace::{ + menu::Confirm, Item, ItemNavHistory, Pane, ToolbarItemLocation, ToolbarItemView, Workspace, +}; -actions!(project_search, [Deploy, Search, SearchInNew, ToggleFocus]); +actions!(project_search, [Deploy, SearchInNew, ToggleFocus]); const MAX_TAB_TITLE_LEN: usize = 24; @@ -530,7 +532,7 @@ impl ProjectSearchBar { } } - fn search(&mut self, _: &Search, cx: &mut ViewContext) { + fn search(&mut self, _: &Confirm, cx: &mut ViewContext) { if let Some(search_view) = self.active_project_search.as_ref() { search_view.update(cx, |search_view, cx| search_view.search(cx)); }