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
284 "ctrl-w o": "workspace::CloseInactiveTabsAndPanes",284 "ctrl-w o": "workspace::CloseInactiveTabsAndPanes",
285 "ctrl-w ctrl-o": "workspace::CloseInactiveTabsAndPanes",285 "ctrl-w ctrl-o": "workspace::CloseInactiveTabsAndPanes",
286 "ctrl-w n": ["workspace::NewFileInDirection", "Up"],286 "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"
288 }289 }
289 },290 },
290 {291 {
crates/editor/src/actions.rs+1−1
@@ -112,7 +112,7 @@ impl_actions!( · 111 unmodified lines
112 MoveUpByLines,112 MoveUpByLines,
113 MoveDownByLines,113 MoveDownByLines,
114 SelectUpByLines,114 SelectUpByLines,
115 SelectDownByLines,115 SelectDownByLines
116 ]116 ]
117);117);
118 118
crates/workspace/src/pane.rs+14−8
@@ -72,10 +72,10 @@ pub struct CloseAllItems { · 71 unmodified lines
72 pub save_intent: Option<SaveIntent>,72 pub save_intent: Option<SaveIntent>,
73}73}
74 74
75#[derive(Clone, PartialEq, Debug, Deserialize)]75#[derive(Clone, PartialEq, Debug, Deserialize, Default)]
76#[serde(rename_all = "camelCase")]76#[serde(rename_all = "camelCase")]
77pub struct RevealInProjectPanel {77pub struct RevealInProjectPanel {
78 pub entry_id: u64,78 pub entry_id: Option<u64>,
79}79}
80 80
81impl_actions!(81impl_actions!(
@@ -1442,7 +1442,9 @@ impl Pane { · 1360 unmodified lines
1442 let entry_id = entry.to_proto();1442 let entry_id = entry.to_proto();
1443 menu = menu.separator().entry(1443 menu = menu.separator().entry(
1444 "Reveal In Project Panel",1444 "Reveal In Project Panel",
1445 Some(Box::new(RevealInProjectPanel { entry_id })),1445 Some(Box::new(RevealInProjectPanel {
1446 entry_id: Some(entry_id),
1447 })),
1446 cx.handler_for(&pane, move |pane, cx| {1448 cx.handler_for(&pane, move |pane, cx| {
1447 pane.project.update(cx, |_, cx| {1449 pane.project.update(cx, |_, cx| {
1448 cx.emit(project::Event::RevealInProjectPanel(1450 cx.emit(project::Event::RevealInProjectPanel(
@@ -1807,11 +1809,15 @@ impl Render for Pane { · 358 unmodified lines
1807 )1809 )
1808 .on_action(1810 .on_action(
1809 cx.listener(|pane: &mut Self, action: &RevealInProjectPanel, cx| {1811 cx.listener(|pane: &mut Self, action: &RevealInProjectPanel, cx| {
1810 pane.project.update(cx, |_, cx| {1812 let entry_id = action
1811 cx.emit(project::Event::RevealInProjectPanel(1813 .entry_id
1812 ProjectEntryId::from_proto(action.entry_id),1814 .map(ProjectEntryId::from_proto)
1813 ))1815 .or_else(|| pane.active_item()?.project_entry_ids(cx).first().copied());
1814 })1816 if let Some(entry_id) = entry_id {
1817 pane.project.update(cx, |_, cx| {
1818 cx.emit(project::Event::RevealInProjectPanel(entry_id))
1819 });
1820 }
1815 }),1821 }),
1816 )1822 )
1817 .when(self.active_item().is_some(), |pane| {1823 .when(self.active_item().is_some(), |pane| {