project_panel: Open file in editor on paste action when single entry (#25555)

Closes #25145

Now, upon pasting a file into the project panel after a copy or cut
operation, it will open in the editor. This buffer in the editor will be
in focus if there is no need to rename the newly pasted file. If a
rename is pending, it simply focuses on the rename editor.


https://github.com/user-attachments/assets/563b22ec-d1f6-4d92-af18-29d10620832c


Future: After the rename is completed, we can decide to focus on the
editor buffer, but this will be addressed in a follow-up, as there will
be multiple cases, such as renaming via a paste action where we want to
focus, and renaming directly via a rename action where we might not want
to focus.

Release Notes:

- Fixed scenario where pasting a file in the project panel after a
copy/cut operation wouldn't automatically open it in the editor.
This commit is contained in:
smit 2025-02-25 16:39:16 +05:30 committed by GitHub
parent 3a041cac72
commit 796e87ecbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2108,12 +2108,12 @@ impl ProjectPanel {
match task { match task {
PasteTask::Rename(task) => { PasteTask::Rename(task) => {
if let Some(CreatedEntry::Included(entry)) = task.await.log_err() { if let Some(CreatedEntry::Included(entry)) = task.await.log_err() {
last_succeed = Some(entry.id); last_succeed = Some(entry);
} }
} }
PasteTask::Copy(task) => { PasteTask::Copy(task) => {
if let Some(Some(entry)) = task.await.log_err() { if let Some(Some(entry)) = task.await.log_err() {
last_succeed = Some(entry.id); last_succeed = Some(entry);
if need_delete { if need_delete {
need_delete_ids.push(entry_id); need_delete_ids.push(entry_id);
} }
@ -2133,17 +2133,31 @@ impl ProjectPanel {
.await?; .await?;
} }
// update selection // update selection
if let Some(entry_id) = last_succeed { if let Some(entry) = last_succeed {
project_panel project_panel
.update_in(&mut cx, |project_panel, window, cx| { .update_in(&mut cx, |project_panel, window, cx| {
project_panel.selection = Some(SelectedEntry { project_panel.selection = Some(SelectedEntry {
worktree_id, worktree_id,
entry_id, entry_id: entry.id,
}); });
if item_count == 1 {
// open entry if not dir, and only focus if rename is not pending
if !entry.is_dir() {
project_panel.open_entry(
entry.id,
disambiguation_range.is_none(),
false,
cx,
);
}
// if only one entry was pasted and it was disambiguated, open the rename editor // if only one entry was pasted and it was disambiguated, open the rename editor
if item_count == 1 && disambiguation_range.is_some() { if disambiguation_range.is_some() {
project_panel.rename_impl(disambiguation_range, window, cx); cx.defer_in(window, |this, window, cx| {
this.rename_impl(disambiguation_range, window, cx);
});
}
} }
}) })
.ok(); .ok();
@ -5877,7 +5891,7 @@ mod tests {
// //
"v root1", "v root1",
" one.txt", " one.txt",
" [EDITOR: 'one copy.txt'] <== selected", " [EDITOR: 'one copy.txt'] <== selected <== marked",
" one.two.txt", " one.two.txt",
] ]
); );
@ -5905,7 +5919,7 @@ mod tests {
"v root1", "v root1",
" one.txt", " one.txt",
" one copy.txt", " one copy.txt",
" [EDITOR: 'one copy 1.txt'] <== selected", " [EDITOR: 'one copy 1.txt'] <== selected <== marked",
" one.two.txt", " one.two.txt",
] ]
); );
@ -5978,7 +5992,7 @@ mod tests {
" > b", " > b",
" four.txt", " four.txt",
" one.txt", " one.txt",
" three.txt <== selected", " three.txt <== selected <== marked",
" two.txt", " two.txt",
] ]
); );
@ -6006,7 +6020,7 @@ mod tests {
" > b", " > b",
" four.txt", " four.txt",
" one.txt", " one.txt",
" three.txt", " three.txt <== marked",
" two.txt", " two.txt",
] ]
); );
@ -6076,7 +6090,7 @@ mod tests {
" > b", " > b",
" four.txt", " four.txt",
" one.txt", " one.txt",
" three.txt <== selected", " three.txt <== selected <== marked",
" two.txt", " two.txt",
] ]
); );
@ -6106,7 +6120,7 @@ mod tests {
" four.txt", " four.txt",
" one.txt", " one.txt",
" three.txt", " three.txt",
" [EDITOR: 'three copy.txt'] <== selected", " [EDITOR: 'three copy.txt'] <== selected <== marked",
" two.txt", " two.txt",
] ]
); );