From 8fed9aaec29607e2719ee0a863eb75c9f44c39b7 Mon Sep 17 00:00:00 2001 From: Alfred Kristal Ern <83819096+KristalAlfred@users.noreply.github.com> Date: Fri, 2 Feb 2024 10:17:46 +0100 Subject: [PATCH] Fix project panel selection related issues (#7245) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #7003 and #7005. Selecting as a reaction to actually opening a new item doesn’t seem robust in all cases, the PR improves that. Release Notes: - Fixed missing project panel file selection in certain cases --- crates/project_panel/src/project_panel.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index f64099340ce5c892831f1503074469afc981d9a1..b43b5d84131e5d1f110224d50ed62b8df4db6969 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -262,11 +262,14 @@ impl ProjectPanel { if let Some(worktree) = project.read(cx).worktree_for_entry(entry_id, cx) { if let Some(entry) = worktree.read(cx).entry_for_id(entry_id) { let file_path = entry.path.clone(); + let worktree_id = worktree.read(cx).id(); + let entry_id = entry.id; + workspace .open_path( ProjectPath { - worktree_id: worktree.read(cx).id(), - path: entry.path.clone(), + worktree_id, + path: file_path.clone(), }, None, focus_opened_item, @@ -281,8 +284,16 @@ impl ProjectPanel { _ => None, } }); - if !focus_opened_item { - if let Some(project_panel) = project_panel.upgrade() { + + if let Some(project_panel) = project_panel.upgrade() { + // Always select the entry, regardless of whether it is opened or not. + project_panel.update(cx, |project_panel, _| { + project_panel.selection = Some(Selection { + worktree_id, + entry_id + }); + }); + if !focus_opened_item { let focus_handle = project_panel.read(cx).focus_handle.clone(); cx.focus(&focus_handle); }