diff --git a/Cargo.lock b/Cargo.lock index aa57d369e6..581817b770 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11845,6 +11845,7 @@ dependencies = [ "unindent", "util", "workspace", + "zed_actions", ] [[package]] diff --git a/assets/keymaps/default-macos.json b/assets/keymaps/default-macos.json index 5b0995084b..0f708dfc47 100644 --- a/assets/keymaps/default-macos.json +++ b/assets/keymaps/default-macos.json @@ -286,7 +286,8 @@ "alt-enter": "search::SelectAllMatches", "cmd-f": "search::FocusSearch", "cmd-alt-f": "search::ToggleReplace", - "cmd-alt-l": "search::ToggleSelection" + "cmd-alt-l": "search::ToggleSelection", + "cmd-shift-o": "outline::Toggle" } }, { diff --git a/crates/search/Cargo.toml b/crates/search/Cargo.toml index 5a9c6409c3..3f06b42287 100644 --- a/crates/search/Cargo.toml +++ b/crates/search/Cargo.toml @@ -40,6 +40,7 @@ theme.workspace = true ui.workspace = true util.workspace = true workspace.workspace = true +zed_actions.workspace = true [dev-dependencies] client = { workspace = true, features = ["test-support"] } diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index 3a9a48e085..a2216e4cbf 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -28,6 +28,7 @@ use serde::Deserialize; use settings::Settings; use std::sync::Arc; use theme::ThemeSettings; +use zed_actions::outline::ToggleOutline; use ui::{ h_flex, prelude::*, utils::SearchInputWidth, IconButton, IconButtonShape, IconName, Tooltip, @@ -482,6 +483,11 @@ impl Render for BufferSearchBar { .on_action(cx.listener(Self::dismiss)) .on_action(cx.listener(Self::select_next_match)) .on_action(cx.listener(Self::select_prev_match)) + .on_action(cx.listener(|this, _: &ToggleOutline, window, cx| { + if let Some(active_searchable_item) = &mut this.active_searchable_item { + active_searchable_item.relay_action(Box::new(ToggleOutline), window, cx); + } + })) .when(self.supported_options(cx).replacement, |this| { this.on_action(cx.listener(Self::toggle_replace)) .when(in_replace, |this| { diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index 8a2463d199..592f867c4a 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -13,8 +13,8 @@ use client::{ }; use futures::{channel::mpsc, StreamExt}; use gpui::{ - AnyElement, AnyView, App, Context, Entity, EntityId, EventEmitter, FocusHandle, Focusable, - Font, HighlightStyle, Pixels, Point, Render, SharedString, Task, WeakEntity, Window, + Action, AnyElement, AnyView, App, Context, Entity, EntityId, EventEmitter, FocusHandle, + Focusable, Font, HighlightStyle, Pixels, Point, Render, SharedString, Task, WeakEntity, Window, }; use project::{Project, ProjectEntryId, ProjectPath}; use schemars::JsonSchema; @@ -518,6 +518,7 @@ pub trait ItemHandle: 'static + Send { fn workspace_settings<'a>(&self, cx: &'a App) -> &'a WorkspaceSettings; fn preserve_preview(&self, cx: &App) -> bool; fn include_in_nav_history(&self) -> bool; + fn relay_action(&self, action: Box, window: &mut Window, cx: &mut App); } pub trait WeakItemHandle: Send + Sync { @@ -978,6 +979,13 @@ impl ItemHandle for Entity { fn include_in_nav_history(&self) -> bool { T::include_in_nav_history() } + + fn relay_action(&self, action: Box, window: &mut Window, cx: &mut App) { + self.update(cx, |this, cx| { + this.focus_handle(cx).focus(window); + window.dispatch_action(action, cx); + }) + } } impl From> for AnyView {