Centralize the CopyPath and CopyRelativePath actions to zed_actions (#24836)

I spent an hour with @marcospb19 this morning debugging an issue with
adding `Copy Path` and `Copy Relative Path` actions to the editor
context menu. Turned out that the problem was using
`workspace::CopyPath` in the menu and `editor::CopyPath` in the action
handler.

This is an easy mistake to make, so let's fix it for everyone.

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-02-13 15:30:44 -08:00 committed by GitHub
parent 28c667a3c7
commit 5d26ce14d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 84 additions and 31 deletions

3
Cargo.lock generated
View file

@ -8984,6 +8984,7 @@ dependencies = [
"util", "util",
"workspace", "workspace",
"worktree", "worktree",
"zed_actions",
] ]
[[package]] [[package]]
@ -10179,6 +10180,7 @@ dependencies = [
"util", "util",
"workspace", "workspace",
"worktree", "worktree",
"zed_actions",
] ]
[[package]] [[package]]
@ -16248,6 +16250,7 @@ dependencies = [
"ui", "ui",
"util", "util",
"uuid", "uuid",
"zed_actions",
] ]
[[package]] [[package]]

View file

@ -650,8 +650,8 @@
"right": "outline_panel::ExpandSelectedEntry", "right": "outline_panel::ExpandSelectedEntry",
"alt-copy": "outline_panel::CopyPath", "alt-copy": "outline_panel::CopyPath",
"ctrl-alt-c": "outline_panel::CopyPath", "ctrl-alt-c": "outline_panel::CopyPath",
"alt-shift-copy": "outline_panel::CopyRelativePath", "alt-shift-copy": "workspace::CopyRelativePath",
"alt-ctrl-shift-c": "outline_panel::CopyRelativePath", "alt-ctrl-shift-c": "workspace::CopyRelativePath",
"alt-ctrl-r": "outline_panel::RevealInFileManager", "alt-ctrl-r": "outline_panel::RevealInFileManager",
"space": "outline_panel::Open", "space": "outline_panel::Open",
"shift-down": "menu::SelectNext", "shift-down": "menu::SelectNext",
@ -679,8 +679,8 @@
"ctrl-v": "project_panel::Paste", "ctrl-v": "project_panel::Paste",
"alt-copy": "project_panel::CopyPath", "alt-copy": "project_panel::CopyPath",
"ctrl-alt-c": "project_panel::CopyPath", "ctrl-alt-c": "project_panel::CopyPath",
"alt-shift-copy": "project_panel::CopyRelativePath", "alt-shift-copy": "workspace::CopyRelativePath",
"alt-ctrl-shift-c": "project_panel::CopyRelativePath", "alt-ctrl-shift-c": "workspace::CopyRelativePath",
"enter": "project_panel::Rename", "enter": "project_panel::Rename",
"f2": "project_panel::Rename", "f2": "project_panel::Rename",
"backspace": ["project_panel::Trash", { "skip_prompt": false }], "backspace": ["project_panel::Trash", { "skip_prompt": false }],

View file

@ -670,8 +670,8 @@
"escape": "menu::Cancel", "escape": "menu::Cancel",
"left": "outline_panel::CollapseSelectedEntry", "left": "outline_panel::CollapseSelectedEntry",
"right": "outline_panel::ExpandSelectedEntry", "right": "outline_panel::ExpandSelectedEntry",
"cmd-alt-c": "outline_panel::CopyPath", "cmd-alt-c": "workspace::CopyPath",
"alt-cmd-shift-c": "outline_panel::CopyRelativePath", "alt-cmd-shift-c": "workspace::CopyRelativePath",
"alt-cmd-r": "outline_panel::RevealInFileManager", "alt-cmd-r": "outline_panel::RevealInFileManager",
"space": "outline_panel::Open", "space": "outline_panel::Open",
"shift-down": "menu::SelectNext", "shift-down": "menu::SelectNext",
@ -692,8 +692,8 @@
"cmd-x": "project_panel::Cut", "cmd-x": "project_panel::Cut",
"cmd-c": "project_panel::Copy", "cmd-c": "project_panel::Copy",
"cmd-v": "project_panel::Paste", "cmd-v": "project_panel::Paste",
"cmd-alt-c": "project_panel::CopyPath", "cmd-alt-c": "workspace::CopyPath",
"alt-cmd-shift-c": "project_panel::CopyRelativePath", "alt-cmd-shift-c": "workspace::CopyRelativePath",
"enter": "project_panel::Rename", "enter": "project_panel::Rename",
"f2": "project_panel::Rename", "f2": "project_panel::Rename",
"backspace": ["project_panel::Trash", { "skip_prompt": false }], "backspace": ["project_panel::Trash", { "skip_prompt": false }],

View file

@ -267,9 +267,7 @@ gpui::actions!(
CopyHighlightJson, CopyHighlightJson,
CopyFileName, CopyFileName,
CopyFileNameWithoutExtension, CopyFileNameWithoutExtension,
CopyPath,
CopyPermalinkToLine, CopyPermalinkToLine,
CopyRelativePath,
Cut, Cut,
CutToEndOfLine, CutToEndOfLine,
Delete, Delete,

View file

@ -13106,7 +13106,12 @@ impl Editor {
} }
} }
pub fn copy_path(&mut self, _: &CopyPath, _window: &mut Window, cx: &mut Context<Self>) { pub fn copy_path(
&mut self,
_: &zed_actions::workspace::CopyPath,
_window: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(path) = self.target_file_abs_path(cx) { if let Some(path) = self.target_file_abs_path(cx) {
if let Some(path) = path.to_str() { if let Some(path) = path.to_str() {
cx.write_to_clipboard(ClipboardItem::new_string(path.to_string())); cx.write_to_clipboard(ClipboardItem::new_string(path.to_string()));
@ -13116,7 +13121,7 @@ impl Editor {
pub fn copy_relative_path( pub fn copy_relative_path(
&mut self, &mut self,
_: &CopyRelativePath, _: &zed_actions::workspace::CopyRelativePath,
_window: &mut Window, _window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) { ) {

View file

@ -38,6 +38,7 @@ ui.workspace = true
util.workspace = true util.workspace = true
workspace.workspace = true workspace.workspace = true
worktree.workspace = true worktree.workspace = true
zed_actions.workspace = true
[dev-dependencies] [dev-dependencies]
search = { workspace = true, features = ["test-support"] } search = { workspace = true, features = ["test-support"] }

View file

@ -67,8 +67,6 @@ actions!(
[ [
CollapseAllEntries, CollapseAllEntries,
CollapseSelectedEntry, CollapseSelectedEntry,
CopyPath,
CopyRelativePath,
ExpandAllEntries, ExpandAllEntries,
ExpandSelectedEntry, ExpandSelectedEntry,
FoldDirectory, FoldDirectory,
@ -1361,8 +1359,11 @@ impl OutlinePanel {
menu.action("Fold Directory", Box::new(FoldDirectory)) menu.action("Fold Directory", Box::new(FoldDirectory))
}) })
.separator() .separator()
.action("Copy Path", Box::new(CopyPath)) .action("Copy Path", Box::new(zed_actions::workspace::CopyPath))
.action("Copy Relative Path", Box::new(CopyRelativePath)) .action(
"Copy Relative Path",
Box::new(zed_actions::workspace::CopyRelativePath),
)
}); });
window.focus(&context_menu.focus_handle(cx)); window.focus(&context_menu.focus_handle(cx));
let subscription = cx.subscribe(&context_menu, |outline_panel, _, _: &DismissEvent, cx| { let subscription = cx.subscribe(&context_menu, |outline_panel, _, _: &DismissEvent, cx| {
@ -1827,7 +1828,12 @@ impl OutlinePanel {
}) })
} }
fn copy_path(&mut self, _: &CopyPath, _: &mut Window, cx: &mut Context<Self>) { fn copy_path(
&mut self,
_: &zed_actions::workspace::CopyPath,
_: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(clipboard_text) = self if let Some(clipboard_text) = self
.selected_entry() .selected_entry()
.and_then(|entry| self.abs_path(entry, cx)) .and_then(|entry| self.abs_path(entry, cx))
@ -1837,7 +1843,12 @@ impl OutlinePanel {
} }
} }
fn copy_relative_path(&mut self, _: &CopyRelativePath, _: &mut Window, cx: &mut Context<Self>) { fn copy_relative_path(
&mut self,
_: &zed_actions::workspace::CopyRelativePath,
_: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(clipboard_text) = self if let Some(clipboard_text) = self
.selected_entry() .selected_entry()
.and_then(|entry| match entry { .and_then(|entry| match entry {

View file

@ -39,6 +39,7 @@ client.workspace = true
worktree.workspace = true worktree.workspace = true
workspace.workspace = true workspace.workspace = true
language.workspace = true language.workspace = true
zed_actions.workspace = true
[dev-dependencies] [dev-dependencies]
client = { workspace = true, features = ["test-support"] } client = { workspace = true, features = ["test-support"] }

View file

@ -186,8 +186,6 @@ actions!(
NewDirectory, NewDirectory,
NewFile, NewFile,
Copy, Copy,
CopyPath,
CopyRelativePath,
Duplicate, Duplicate,
RevealInFileManager, RevealInFileManager,
RemoveFromProject, RemoveFromProject,
@ -730,8 +728,11 @@ impl ProjectPanel {
} }
}) })
.separator() .separator()
.action("Copy Path", Box::new(CopyPath)) .action("Copy Path", Box::new(zed_actions::workspace::CopyPath))
.action("Copy Relative Path", Box::new(CopyRelativePath)) .action(
"Copy Relative Path",
Box::new(zed_actions::workspace::CopyRelativePath),
)
.separator() .separator()
.when(!is_root || !cfg!(target_os = "windows"), |menu| { .when(!is_root || !cfg!(target_os = "windows"), |menu| {
menu.action("Rename", Box::new(Rename)) menu.action("Rename", Box::new(Rename))
@ -2161,7 +2162,12 @@ impl ProjectPanel {
self.paste(&Paste {}, window, cx); self.paste(&Paste {}, window, cx);
} }
fn copy_path(&mut self, _: &CopyPath, _: &mut Window, cx: &mut Context<Self>) { fn copy_path(
&mut self,
_: &zed_actions::workspace::CopyPath,
_: &mut Window,
cx: &mut Context<Self>,
) {
let abs_file_paths = { let abs_file_paths = {
let project = self.project.read(cx); let project = self.project.read(cx);
self.effective_entries() self.effective_entries()
@ -2185,7 +2191,12 @@ impl ProjectPanel {
} }
} }
fn copy_relative_path(&mut self, _: &CopyRelativePath, _: &mut Window, cx: &mut Context<Self>) { fn copy_relative_path(
&mut self,
_: &zed_actions::workspace::CopyRelativePath,
_: &mut Window,
cx: &mut Context<Self>,
) {
let file_paths = { let file_paths = {
let project = self.project.read(cx); let project = self.project.read(cx);
self.effective_entries() self.effective_entries()

View file

@ -63,6 +63,7 @@ theme.workspace = true
ui.workspace = true ui.workspace = true
util.workspace = true util.workspace = true
uuid.workspace = true uuid.workspace = true
zed_actions.workspace = true
[dev-dependencies] [dev-dependencies]
call = { workspace = true, features = ["test-support"] } call = { workspace = true, features = ["test-support"] }

View file

@ -7,8 +7,8 @@ use crate::{
notifications::NotifyResultExt, notifications::NotifyResultExt,
toolbar::Toolbar, toolbar::Toolbar,
workspace_settings::{AutosaveSetting, TabBarSettings, WorkspaceSettings}, workspace_settings::{AutosaveSetting, TabBarSettings, WorkspaceSettings},
CloseWindow, CopyPath, CopyRelativePath, NewFile, NewTerminal, OpenInTerminal, OpenTerminal, CloseWindow, NewFile, NewTerminal, OpenInTerminal, OpenTerminal, OpenVisible, SplitDirection,
OpenVisible, SplitDirection, ToggleFileFinder, ToggleProjectSymbols, ToggleZoom, Workspace, ToggleFileFinder, ToggleProjectSymbols, ToggleZoom, Workspace,
}; };
use anyhow::Result; use anyhow::Result;
use collections::{BTreeSet, HashMap, HashSet, VecDeque}; use collections::{BTreeSet, HashMap, HashSet, VecDeque};
@ -2552,7 +2552,7 @@ impl Pane {
.when_some(entry_abs_path, |menu, abs_path| { .when_some(entry_abs_path, |menu, abs_path| {
menu.entry( menu.entry(
"Copy Path", "Copy Path",
Some(Box::new(CopyPath)), Some(Box::new(zed_actions::workspace::CopyPath)),
window.handler_for(&pane, move |_, _, cx| { window.handler_for(&pane, move |_, _, cx| {
cx.write_to_clipboard(ClipboardItem::new_string( cx.write_to_clipboard(ClipboardItem::new_string(
abs_path.to_string_lossy().to_string(), abs_path.to_string_lossy().to_string(),
@ -2563,7 +2563,7 @@ impl Pane {
.when_some(relative_path, |menu, relative_path| { .when_some(relative_path, |menu, relative_path| {
menu.entry( menu.entry(
"Copy Relative Path", "Copy Relative Path",
Some(Box::new(CopyRelativePath)), Some(Box::new(zed_actions::workspace::CopyRelativePath)),
window.handler_for(&pane, move |_, _, cx| { window.handler_for(&pane, move |_, _, cx| {
cx.write_to_clipboard(ClipboardItem::new_string( cx.write_to_clipboard(ClipboardItem::new_string(
relative_path.to_string_lossy().to_string(), relative_path.to_string_lossy().to_string(),

View file

@ -133,8 +133,6 @@ actions!(
ClearAllNotifications, ClearAllNotifications,
CloseAllDocks, CloseAllDocks,
CloseWindow, CloseWindow,
CopyPath,
CopyRelativePath,
Feedback, Feedback,
FollowNextCollaborator, FollowNextCollaborator,
MoveFocusedPanelToNextPosition, MoveFocusedPanelToNextPosition,

View file

@ -43,10 +43,34 @@ actions!(
ResetBufferFontSize, ResetBufferFontSize,
DecreaseUiFontSize, DecreaseUiFontSize,
IncreaseUiFontSize, IncreaseUiFontSize,
ResetUiFontSize ResetUiFontSize,
] ]
); );
pub mod workspace {
use gpui::action_with_deprecated_aliases;
action_with_deprecated_aliases!(
workspace,
CopyPath,
[
"editor::CopyPath",
"outline_panel::CopyPath",
"project_panel::CopyPath"
]
);
action_with_deprecated_aliases!(
workspace,
CopyRelativePath,
[
"editor::CopyRelativePath",
"outline_panel::CopyRelativePath",
"project_panel::CopyRelativePath"
]
);
}
pub mod git { pub mod git {
use gpui::action_with_deprecated_aliases; use gpui::action_with_deprecated_aliases;