Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to copy current file name #22174

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/editor/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ gpui::actions!(
ConvertToUpperCase,
Copy,
CopyFileLocation,
CopyFileName,
CopyFileNameWithoutExtension,
CopyHighlightJson,
CopyPath,
CopyPermalinkToLine,
Expand Down
24 changes: 24 additions & 0 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11728,6 +11728,30 @@ impl Editor {
}
}

pub fn copy_file_name_without_extension(
&mut self,
_: &CopyFileNameWithoutExtension,
cx: &mut ViewContext<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, cx: &mut ViewContext<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, cx: &mut ViewContext<Self>) {
self.show_git_blame_gutter = !self.show_git_blame_gutter;

Expand Down
2 changes: 2 additions & 0 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ impl EditorElement {
register_action(view, cx, Editor::reveal_in_finder);
register_action(view, cx, Editor::copy_path);
register_action(view, cx, Editor::copy_relative_path);
register_action(view, cx, Editor::copy_file_name);
register_action(view, cx, Editor::copy_file_name_without_extension);
register_action(view, cx, Editor::copy_highlight_json);
register_action(view, cx, Editor::copy_permalink_to_line);
register_action(view, cx, Editor::open_permalink_to_line);
Expand Down
Loading