Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add command to copy current file name (#22174)
ANKDDEV7fe6943d89c7
diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rsindex 27266f3dd6e..61481e3f921 100644--- a/crates/editor/src/actions.rs+++ b/crates/editor/src/actions.rs@@ -265,6 +265,8 @@ gpui::actions!(Copy,CopyFileLocation,CopyHighlightJson,+ CopyFileName,+ CopyFileNameWithoutExtension,CopyPath,CopyPermalinkToLine,CopyRelativePath,diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 957648f4b8a..a95d276113d 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -13116,6 +13116,31 @@ impl Editor {}}+ pub fn copy_file_name_without_extension(+ &mut self,+ _: &CopyFileNameWithoutExtension,+ _: &mut Window,+ cx: &mut Context<Self>,+ ) {+ if let Some(file) = self.target_file(cx) {+ if let Some(file_stem) = file.path().file_stem() {+ if let Some(name) = file_stem.to_str() {+ cx.write_to_clipboard(ClipboardItem::new_string(name.to_string()));+ }+ }+ }+ }++ pub fn copy_file_name(&mut self, _: &CopyFileName, _: &mut Window, cx: &mut Context<Self>) {+ if let Some(file) = self.target_file(cx) {+ if let Some(file_name) = file.path().file_name() {+ if let Some(name) = file_name.to_str() {+ cx.write_to_clipboard(ClipboardItem::new_string(name.to_string()));+ }+ }+ }+ }+pub fn toggle_git_blame(&mut self,_: &ToggleGitBlame,diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 377a6205942..6d7a6d274e1 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -408,6 +408,8 @@ impl EditorElement {register_action(editor, window, Editor::reveal_in_finder);register_action(editor, window, Editor::copy_path);register_action(editor, window, Editor::copy_relative_path);+ register_action(editor, window, Editor::copy_file_name);+ register_action(editor, window, Editor::copy_file_name_without_extension);register_action(editor, window, Editor::copy_highlight_json);register_action(editor, window, Editor::copy_permalink_to_line);register_action(editor, window, Editor::open_permalink_to_line);