tab: Fix copy wrong relative path for tab (#19206)
Some checks are pending
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Linux) Build Remote Server (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run

Closes #19204 

Release Notes:

- Fixed relative paths copied incorrectly from tabs
([#19204](https://github.com/zed-industries/zed/issues/19204))
This commit is contained in:
CharlesChen0823 2024-10-15 14:27:34 +08:00 committed by GitHub
parent 41ba4178fc
commit 62de03f286
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1747,17 +1747,6 @@ impl Pane {
}
}
fn copy_relative_path(&mut self, _: &CopyRelativePath, cx: &mut ViewContext<Self>) {
if let Some(clipboard_text) = self
.active_item()
.as_ref()
.and_then(|entry| entry.project_path(cx))
.map(|p| p.path.to_string_lossy().to_string())
{
cx.write_to_clipboard(ClipboardItem::new_string(clipboard_text));
}
}
pub fn icon_color(selected: bool) -> Color {
if selected {
Color::Default
@ -2102,6 +2091,11 @@ impl Pane {
let parent_abs_path = entry_abs_path
.as_deref()
.and_then(|abs_path| Some(abs_path.parent()?.to_path_buf()));
let relative_path = pane
.read(cx)
.item_for_entry(entry, cx)
.and_then(|item| item.project_path(cx))
.map(|project_path| project_path.path);
let entry_id = entry.to_proto();
menu = menu
@ -2117,13 +2111,17 @@ impl Pane {
}),
)
})
.entry(
.when_some(relative_path, |menu, relative_path| {
menu.entry(
"Copy Relative Path",
Some(Box::new(CopyRelativePath)),
cx.handler_for(&pane, move |pane, cx| {
pane.copy_relative_path(&CopyRelativePath, cx);
cx.handler_for(&pane, move |_, cx| {
cx.write_to_clipboard(ClipboardItem::new_string(
relative_path.to_string_lossy().to_string(),
));
}),
)
})
.map(pin_tab_entries)
.separator()
.entry(