editor: Fix copy file actions not working in remote environments (#43362)

Closes #42500

Release Notes:

- Fixed all three editor actions not working in remote environments
  - `editor: copy file name`
  - `editor: copy file location`
  - `editor: copy file name without extension`

Here's the before/after:




https://github.com/user-attachments/assets/bfb03e99-2e1a-47a2-bd26-280180154fe3
This commit is contained in:
Mayank Verma
2025-11-24 21:45:12 +00:00
committed by GitHub
parent 769464762a
commit 9e69ac889c
2 changed files with 302 additions and 12 deletions
+17 -10
View File
@@ -20234,18 +20234,20 @@ impl Editor {
_: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(file) = self.target_file(cx)
&& let Some(file_stem) = file.path().file_stem()
{
if let Some(file_stem) = self.active_excerpt(cx).and_then(|(_, buffer, _)| {
let file = buffer.read(cx).file()?;
file.path().file_stem()
}) {
cx.write_to_clipboard(ClipboardItem::new_string(file_stem.to_string()));
}
}
pub fn copy_file_name(&mut self, _: &CopyFileName, _: &mut Window, cx: &mut Context<Self>) {
if let Some(file) = self.target_file(cx)
&& let Some(name) = file.path().file_name()
{
cx.write_to_clipboard(ClipboardItem::new_string(name.to_string()));
if let Some(file_name) = self.active_excerpt(cx).and_then(|(_, buffer, _)| {
let file = buffer.read(cx).file()?;
Some(file.file_name(cx))
}) {
cx.write_to_clipboard(ClipboardItem::new_string(file_name.to_string()));
}
}
@@ -20519,9 +20521,14 @@ impl Editor {
.start
.row
+ 1;
if let Some(file) = self.target_file(cx) {
let path = file.path().display(file.path_style(cx));
cx.write_to_clipboard(ClipboardItem::new_string(format!("{path}:{selection}")));
if let Some(file_location) = self.active_excerpt(cx).and_then(|(_, buffer, _)| {
let project = self.project()?.read(cx);
let file = buffer.read(cx).file()?;
let path = file.path().display(project.path_style(cx));
Some(format!("{path}:{selection}"))
}) {
cx.write_to_clipboard(ClipboardItem::new_string(file_location));
}
}