editor: Fix editor: copy path not working in SSH remoting (#23235)

Closes #23135 

Release Notes:

- Fix `editor: copy path` not work in ssh remote
This commit is contained in:
CharlesChen0823 2025-01-17 11:47:47 +08:00 committed by GitHub
parent 7ee78a4d35
commit f0a07b5eff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11471,6 +11471,24 @@ impl Editor {
.and_then(|f| f.as_local())
}
fn target_file_abs_path(&self, cx: &mut ViewContext<Self>) -> Option<PathBuf> {
self.active_excerpt(cx).and_then(|(_, buffer, _)| {
let project_path = buffer.read(cx).project_path(cx)?;
let project = self.project.as_ref()?.read(cx);
project.absolute_path(&project_path, cx)
})
}
fn target_file_path(&self, cx: &mut ViewContext<Self>) -> Option<PathBuf> {
self.active_excerpt(cx).and_then(|(_, buffer, _)| {
let project_path = buffer.read(cx).project_path(cx)?;
let project = self.project.as_ref()?.read(cx);
let entry = project.entry_for_path(&project_path, cx)?;
let path = entry.path.to_path_buf();
Some(path)
})
}
pub fn reveal_in_finder(&mut self, _: &RevealInFileManager, cx: &mut ViewContext<Self>) {
if let Some(target) = self.target_file(cx) {
cx.reveal_path(&target.abs_path(cx));
@ -11478,16 +11496,16 @@ impl Editor {
}
pub fn copy_path(&mut self, _: &CopyPath, cx: &mut ViewContext<Self>) {
if let Some(file) = self.target_file(cx) {
if let Some(path) = file.abs_path(cx).to_str() {
if let Some(path) = self.target_file_abs_path(cx) {
if let Some(path) = path.to_str() {
cx.write_to_clipboard(ClipboardItem::new_string(path.to_string()));
}
}
}
pub fn copy_relative_path(&mut self, _: &CopyRelativePath, cx: &mut ViewContext<Self>) {
if let Some(file) = self.target_file(cx) {
if let Some(path) = file.path().to_str() {
if let Some(path) = self.target_file_path(cx) {
if let Some(path) = path.to_str() {
cx.write_to_clipboard(ClipboardItem::new_string(path.to_string()));
}
}