From dd7b874039a6f6097ee91655ad0f114ea6f585a1 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 16 Jun 2022 11:30:02 -0700 Subject: [PATCH] Return focus to the workspace center on escape --- Cargo.lock | 1 + crates/contacts_panel/src/contacts_panel.rs | 13 +++++++++++-- crates/workspace/Cargo.toml | 1 + crates/workspace/src/workspace.rs | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 352c3310ff76a53e88030b42514fa7702f9eebf8..c1295012c7398b1c398cd0acea69c6cf69ab221c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5980,6 +5980,7 @@ dependencies = [ "gpui", "language", "log", + "menu", "parking_lot 0.11.2", "postage", "project", diff --git a/crates/contacts_panel/src/contacts_panel.rs b/crates/contacts_panel/src/contacts_panel.rs index 9bf9d0fa0b73448f9e17e94aefc21f930b0bd947..72bf27ebeb5a433d061218564782a7950e49fc97 100644 --- a/crates/contacts_panel/src/contacts_panel.rs +++ b/crates/contacts_panel/src/contacts_panel.rs @@ -932,8 +932,17 @@ impl ContactsPanel { } fn clear_filter(&mut self, _: &Cancel, cx: &mut ViewContext) { - self.filter_editor - .update(cx, |editor, cx| editor.set_text("", cx)); + let did_clear = self.filter_editor.update(cx, |editor, cx| { + if editor.buffer().read(cx).len(cx) > 0 { + editor.set_text("", cx); + true + } else { + false + } + }); + if !did_clear { + cx.propagate_action(); + } } fn select_next(&mut self, _: &SelectNext, cx: &mut ViewContext) { diff --git a/crates/workspace/Cargo.toml b/crates/workspace/Cargo.toml index 8b881fe9e524876cf8fd7ebc6e15471fea22be20..81dcad6a128da05357e2d673cae2626f65502422 100644 --- a/crates/workspace/Cargo.toml +++ b/crates/workspace/Cargo.toml @@ -16,6 +16,7 @@ clock = { path = "../clock" } collections = { path = "../collections" } gpui = { path = "../gpui" } language = { path = "../language" } +menu = { path = "../menu" } project = { path = "../project" } settings = { path = "../settings" } theme = { path = "../theme" } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index b8803977f87e6c232f583416d88fefe93a296b05..c86dcd7830d423b440cd680e4e7fa378d5e82b73 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -186,6 +186,7 @@ pub fn init(app_state: Arc, cx: &mut MutableAppContext) { ); cx.add_action(Workspace::toggle_sidebar_item); cx.add_action(Workspace::toggle_sidebar_item_focus); + cx.add_action(Workspace::focus_center); cx.add_action(|workspace: &mut Workspace, _: &ActivatePreviousPane, cx| { workspace.activate_previous_pane(cx) }); @@ -1281,6 +1282,11 @@ impl Workspace { cx.notify(); } + pub fn focus_center(&mut self, _: &menu::Cancel, cx: &mut ViewContext) { + cx.focus_self(); + cx.notify(); + } + fn add_pane(&mut self, cx: &mut ViewContext) -> ViewHandle { let pane = cx.add_view(|cx| Pane::new(cx)); let pane_id = pane.id();