mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-18 18:08:07 +03:00
project_panel: Select the newly created file when copy/pasting a file (#14705)
Closes: #14361 Release Notes: - Improved project panel to select newly created file on copy/paste ([#14361](https://github.com/zed-industries/zed/issues/14361))
This commit is contained in:
parent
ed3d3dc690
commit
bac4a0428d
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -8107,6 +8107,7 @@ dependencies = [
|
|||||||
"db",
|
"db",
|
||||||
"editor",
|
"editor",
|
||||||
"file_icons",
|
"file_icons",
|
||||||
|
"futures 0.3.28",
|
||||||
"git",
|
"git",
|
||||||
"gpui",
|
"gpui",
|
||||||
"language",
|
"language",
|
||||||
|
@ -18,6 +18,7 @@ collections.workspace = true
|
|||||||
db.workspace = true
|
db.workspace = true
|
||||||
editor.workspace = true
|
editor.workspace = true
|
||||||
file_icons.workspace = true
|
file_icons.workspace = true
|
||||||
|
futures.workspace = true
|
||||||
git.workspace = true
|
git.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
menu.workspace = true
|
menu.workspace = true
|
||||||
|
@ -1307,6 +1307,8 @@ impl ProjectPanel {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.filter(|clipboard| !clipboard.items().is_empty())?;
|
.filter(|clipboard| !clipboard.items().is_empty())?;
|
||||||
|
|
||||||
|
let mut tasks = Vec::new();
|
||||||
|
|
||||||
for clipboard_entry in clipboard_entries.items() {
|
for clipboard_entry in clipboard_entries.items() {
|
||||||
if clipboard_entry.worktree_id != worktree_id {
|
if clipboard_entry.worktree_id != worktree_id {
|
||||||
return None;
|
return None;
|
||||||
@ -1318,15 +1320,34 @@ impl ProjectPanel {
|
|||||||
.update(cx, |project, cx| {
|
.update(cx, |project, cx| {
|
||||||
project.rename_entry(clipboard_entry.entry_id, new_path, cx)
|
project.rename_entry(clipboard_entry.entry_id, new_path, cx)
|
||||||
})
|
})
|
||||||
.detach_and_log_err(cx)
|
.detach_and_log_err(cx);
|
||||||
} else {
|
} else {
|
||||||
self.project
|
let task = self.project.update(cx, |project, cx| {
|
||||||
.update(cx, |project, cx| {
|
|
||||||
project.copy_entry(clipboard_entry.entry_id, new_path, cx)
|
project.copy_entry(clipboard_entry.entry_id, new_path, cx)
|
||||||
|
});
|
||||||
|
tasks.push(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.spawn(|project_panel, mut cx| async move {
|
||||||
|
let entry_ids = futures::future::join_all(tasks).await;
|
||||||
|
if let Some(Some(entry)) = entry_ids
|
||||||
|
.into_iter()
|
||||||
|
.rev()
|
||||||
|
.find_map(|entry_id| entry_id.ok())
|
||||||
|
{
|
||||||
|
project_panel
|
||||||
|
.update(&mut cx, |project_panel, _cx| {
|
||||||
|
project_panel.selection = Some(SelectedEntry {
|
||||||
|
worktree_id,
|
||||||
|
entry_id: entry.id,
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.detach_and_log_err(cx)
|
.ok();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
self.expand_entry(worktree_id, entry.id, cx);
|
self.expand_entry(worktree_id, entry.id, cx);
|
||||||
Some(())
|
Some(())
|
||||||
});
|
});
|
||||||
@ -3579,8 +3600,8 @@ mod tests {
|
|||||||
&[
|
&[
|
||||||
//
|
//
|
||||||
"v root1",
|
"v root1",
|
||||||
" one.two copy.txt",
|
" one.two copy.txt <== selected",
|
||||||
" one.two.txt <== selected",
|
" one.two.txt",
|
||||||
" one.txt",
|
" one.txt",
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -3595,9 +3616,9 @@ mod tests {
|
|||||||
&[
|
&[
|
||||||
//
|
//
|
||||||
"v root1",
|
"v root1",
|
||||||
" one.two copy 1.txt",
|
" one.two copy 1.txt <== selected",
|
||||||
" one.two copy.txt",
|
" one.two copy.txt",
|
||||||
" one.two.txt <== selected",
|
" one.two.txt",
|
||||||
" one.txt",
|
" one.txt",
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -3682,10 +3703,13 @@ mod tests {
|
|||||||
visible_entries_as_strings(&panel, 0..50, cx),
|
visible_entries_as_strings(&panel, 0..50, cx),
|
||||||
&[
|
&[
|
||||||
//
|
//
|
||||||
"v root <== selected",
|
"v root",
|
||||||
" > a",
|
" > a",
|
||||||
" > a copy",
|
" v a copy",
|
||||||
" > a copy 1",
|
" > a <== selected",
|
||||||
|
" > inner_dir",
|
||||||
|
" one.txt",
|
||||||
|
" two.txt",
|
||||||
" v b",
|
" v b",
|
||||||
" v a",
|
" v a",
|
||||||
" v inner_dir",
|
" v inner_dir",
|
||||||
|
Loading…
Reference in New Issue
Block a user