From 796e87ecbc3df84e0f5d6e63d2d804a8c28fe94f Mon Sep 17 00:00:00 2001 From: smit <0xtimsb@gmail.com> Date: Tue, 25 Feb 2025 16:39:16 +0530 Subject: [PATCH] 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. --- crates/project_panel/src/project_panel.rs | 40 +++++++++++++++-------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index fd5c230995..1cb66ea3a3 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -2108,12 +2108,12 @@ impl ProjectPanel { match task { PasteTask::Rename(task) => { if let Some(CreatedEntry::Included(entry)) = task.await.log_err() { - last_succeed = Some(entry.id); + last_succeed = Some(entry); } } PasteTask::Copy(task) => { if let Some(Some(entry)) = task.await.log_err() { - last_succeed = Some(entry.id); + last_succeed = Some(entry); if need_delete { need_delete_ids.push(entry_id); } @@ -2133,17 +2133,31 @@ impl ProjectPanel { .await?; } // update selection - if let Some(entry_id) = last_succeed { + if let Some(entry) = last_succeed { project_panel .update_in(&mut cx, |project_panel, window, cx| { project_panel.selection = Some(SelectedEntry { worktree_id, - entry_id, + entry_id: entry.id, }); - // if only one entry was pasted and it was disambiguated, open the rename editor - if item_count == 1 && disambiguation_range.is_some() { - project_panel.rename_impl(disambiguation_range, window, cx); + 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 disambiguation_range.is_some() { + cx.defer_in(window, |this, window, cx| { + this.rename_impl(disambiguation_range, window, cx); + }); + } } }) .ok(); @@ -5877,7 +5891,7 @@ mod tests { // "v root1", " one.txt", - " [EDITOR: 'one copy.txt'] <== selected", + " [EDITOR: 'one copy.txt'] <== selected <== marked", " one.two.txt", ] ); @@ -5905,7 +5919,7 @@ mod tests { "v root1", " one.txt", " one copy.txt", - " [EDITOR: 'one copy 1.txt'] <== selected", + " [EDITOR: 'one copy 1.txt'] <== selected <== marked", " one.two.txt", ] ); @@ -5978,7 +5992,7 @@ mod tests { " > b", " four.txt", " one.txt", - " three.txt <== selected", + " three.txt <== selected <== marked", " two.txt", ] ); @@ -6006,7 +6020,7 @@ mod tests { " > b", " four.txt", " one.txt", - " three.txt", + " three.txt <== marked", " two.txt", ] ); @@ -6076,7 +6090,7 @@ mod tests { " > b", " four.txt", " one.txt", - " three.txt <== selected", + " three.txt <== selected <== marked", " two.txt", ] ); @@ -6106,7 +6120,7 @@ mod tests { " four.txt", " one.txt", " three.txt", - " [EDITOR: 'three copy.txt'] <== selected", + " [EDITOR: 'three copy.txt'] <== selected <== marked", " two.txt", ] );