Fix project panel selection related issues (#7245)

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
This commit is contained in:
Alfred Kristal Ern 2024-02-02 10:17:46 +01:00 committed by GitHub
parent 5ed3b44686
commit 8fed9aaec2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -262,11 +262,14 @@ impl ProjectPanel {
if let Some(worktree) = project.read(cx).worktree_for_entry(entry_id, cx) { 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) { if let Some(entry) = worktree.read(cx).entry_for_id(entry_id) {
let file_path = entry.path.clone(); let file_path = entry.path.clone();
let worktree_id = worktree.read(cx).id();
let entry_id = entry.id;
workspace workspace
.open_path( .open_path(
ProjectPath { ProjectPath {
worktree_id: worktree.read(cx).id(), worktree_id,
path: entry.path.clone(), path: file_path.clone(),
}, },
None, None,
focus_opened_item, focus_opened_item,
@ -281,8 +284,16 @@ impl ProjectPanel {
_ => None, _ => 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(); let focus_handle = project_panel.read(cx).focus_handle.clone();
cx.focus(&focus_handle); cx.focus(&focus_handle);
} }