Cargo.lock 🔗
@@ -5980,6 +5980,7 @@ dependencies = [
"gpui",
"language",
"log",
+ "menu",
"parking_lot 0.11.2",
"postage",
"project",
Max Brunsfeld created
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(-)
@@ -5980,6 +5980,7 @@ dependencies = [
"gpui",
"language",
"log",
+ "menu",
"parking_lot 0.11.2",
"postage",
"project",
@@ -932,8 +932,17 @@ impl ContactsPanel {
}
fn clear_filter(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
- 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<Self>) {
@@ -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" }
@@ -186,6 +186,7 @@ pub fn init(app_state: Arc<AppState>, 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<Self>) {
+ cx.focus_self();
+ cx.notify();
+ }
+
fn add_pane(&mut self, cx: &mut ViewContext<Self>) -> ViewHandle<Pane> {
let pane = cx.add_view(|cx| Pane::new(cx));
let pane_id = pane.id();