History

Add ability to bind to pane::RevealInProjectPanel (#7487)

Previously it wasn't possible to create a keybinding for this action because it required an argument. Now the action takes the active item of the pane and if it's a multi-buffer the first one. This also adds a default keybinding for Vim mode: `-` will reveal the file in the project panel. Fixes #7485. Release Notes: - Added `pane::RevealInProjectPanel` as an action in the command palette. ([#7485](https://github.com/zed-industries/zed/issues/7485)).

Thorsten Ball committed 2 years ago

Commit db39b9d1 parent 2aa8ccd3 files · +17 −10Browse files

Unified · Split

3 files
  1. assets/keymaps/vim.json +2 −1
  2. crates/editor/src/actions.rs +1 −1
  3. crates/workspace/src/pane.rs +14 −8
assets/keymaps/vim.json+2−1
@@ -284,7 +284,8 @@ · 283 unmodified lines
284284 "ctrl-w o": "workspace::CloseInactiveTabsAndPanes",
285285 "ctrl-w ctrl-o": "workspace::CloseInactiveTabsAndPanes",
286286 "ctrl-w n": ["workspace::NewFileInDirection", "Up"],
287− "ctrl-w ctrl-n": ["workspace::NewFileInDirection", "Up"]
287+ "ctrl-w ctrl-n": ["workspace::NewFileInDirection", "Up"],
288+ "-": "pane::RevealInProjectPanel"
288289 }
289290 },
290291 {
crates/editor/src/actions.rs+1−1
@@ -112,7 +112,7 @@ impl_actions!( · 111 unmodified lines
112112 MoveUpByLines,
113113 MoveDownByLines,
114114 SelectUpByLines,
115− SelectDownByLines,
115+ SelectDownByLines
116116 ]
117117 );
118118
crates/workspace/src/pane.rs+14−8
@@ -72,10 +72,10 @@ pub struct CloseAllItems { · 71 unmodified lines
7272 pub save_intent: Option<SaveIntent>,
7373 }
7474
75−#[derive(Clone, PartialEq, Debug, Deserialize)]
75+#[derive(Clone, PartialEq, Debug, Deserialize, Default)]
7676 #[serde(rename_all = "camelCase")]
7777 pub struct RevealInProjectPanel {
78− pub entry_id: u64,
78+ pub entry_id: Option<u64>,
7979 }
8080
8181 impl_actions!(
@@ -1442,7 +1442,9 @@ impl Pane { · 1360 unmodified lines
14421442 let entry_id = entry.to_proto();
14431443 menu = menu.separator().entry(
14441444 "Reveal In Project Panel",
1445− Some(Box::new(RevealInProjectPanel { entry_id })),
1445+ Some(Box::new(RevealInProjectPanel {
1446+ entry_id: Some(entry_id),
1447+ })),
14461448 cx.handler_for(&pane, move |pane, cx| {
14471449 pane.project.update(cx, |_, cx| {
14481450 cx.emit(project::Event::RevealInProjectPanel(
@@ -1807,11 +1809,15 @@ impl Render for Pane { · 358 unmodified lines
18071809 )
18081810 .on_action(
18091811 cx.listener(|pane: &mut Self, action: &RevealInProjectPanel, cx| {
1810− pane.project.update(cx, |_, cx| {
1811− cx.emit(project::Event::RevealInProjectPanel(
1812− ProjectEntryId::from_proto(action.entry_id),
1813− ))
1814− })
1812+ let entry_id = action
1813+ .entry_id
1814+ .map(ProjectEntryId::from_proto)
1815+ .or_else(|| pane.active_item()?.project_entry_ids(cx).first().copied());
1816+ if let Some(entry_id) = entry_id {
1817+ pane.project.update(cx, |_, cx| {
1818+ cx.emit(project::Event::RevealInProjectPanel(entry_id))
1819+ });
1820+ }
18151821 }),
18161822 )
18171823 .when(self.active_item().is_some(), |pane| {