Reuse Confirm action in chat panel, go-to-line, and project search

This commit is contained in:
Max Brunsfeld 2022-04-21 15:24:05 -07:00
parent 915ba91888
commit 490b65b55f
4 changed files with 25 additions and 33 deletions

View file

@ -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"
}
}
]

View file

@ -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<Self>) {
fn send(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
if let Some((channel, _)) = self.active_channel.as_ref() {
let body = self.input_editor.update(cx, |editor, cx| {
let body = editor.text(cx);

View file

@ -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<Self>) {
cx.emit(Event::Dismissed);
}
fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
self.prev_scroll_position.take();
self.active_editor.update(cx, |active_editor, cx| {

View file

@ -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<Self>) {
fn search(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
if let Some(search_view) = self.active_project_search.as_ref() {
search_view.update(cx, |search_view, cx| search_view.search(cx));
}