From eedb29963c6b887c78438c84254ceea9e32891d8 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 26 May 2022 16:45:41 +0200 Subject: [PATCH] Implement `CopyPath` --- assets/keymaps/default.json | 1 + crates/project_panel/src/project_panel.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 1049e216f3..f21138e541 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -352,6 +352,7 @@ "bindings": { "left": "project_panel::CollapseSelectedEntry", "right": "project_panel::ExpandSelectedEntry", + "cmd-alt-c": "project_panel::CopyPath", "f2": "project_panel::Rename", "backspace": "project_panel::Delete" } diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index 5fda6f04fa..f1dac49f81 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -11,8 +11,8 @@ use gpui::{ geometry::vector::Vector2F, impl_internal_actions, keymap, platform::CursorStyle, - AppContext, Element, ElementBox, Entity, ModelHandle, MutableAppContext, PromptLevel, Task, - View, ViewContext, ViewHandle, WeakViewHandle, + AppContext, ClipboardItem, Element, ElementBox, Entity, ModelHandle, MutableAppContext, + PromptLevel, Task, View, ViewContext, ViewHandle, WeakViewHandle, }; use menu::{Confirm, SelectNext, SelectPrev}; use project::{Entry, EntryKind, Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId}; @@ -22,6 +22,7 @@ use std::{ collections::{hash_map, HashMap}, ffi::OsStr, ops::Range, + path::PathBuf, }; use unicase::UniCase; use workspace::Workspace; @@ -621,7 +622,12 @@ impl ProjectPanel { } fn copy_path(&mut self, _: &CopyPath, cx: &mut ViewContext) { - todo!() + if let Some((worktree, entry)) = self.selected_entry(cx) { + let mut path = PathBuf::new(); + path.push(worktree.root_name()); + path.push(&entry.path); + cx.write_to_clipboard(ClipboardItem::new(path.to_string_lossy().to_string())); + } } fn index_for_selection(&self, selection: Selection) -> Option<(usize, usize, usize)> {