Allow creating entries when nothing is selected in the project panel (#29336)
Closes https://github.com/zed-industries/zed/issues/29249 Release Notes: - Allowed creating entries when nothing is selected in the project panel
This commit is contained in:
parent
c0f8e0f605
commit
fcfeea4825
2 changed files with 134 additions and 51 deletions
|
@ -1389,63 +1389,81 @@ impl ProjectPanel {
|
|||
}
|
||||
|
||||
fn add_entry(&mut self, is_dir: bool, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if let Some(SelectedEntry {
|
||||
worktree_id,
|
||||
entry_id,
|
||||
}) = self.selection
|
||||
let Some((worktree_id, entry_id)) = self
|
||||
.selection
|
||||
.map(|entry| (entry.worktree_id, entry.entry_id))
|
||||
.or_else(|| {
|
||||
let entry_id = self.last_worktree_root_id?;
|
||||
let worktree_id = self
|
||||
.project
|
||||
.read(cx)
|
||||
.worktree_for_entry(entry_id, cx)?
|
||||
.read(cx)
|
||||
.id();
|
||||
|
||||
self.selection = Some(SelectedEntry {
|
||||
worktree_id,
|
||||
entry_id,
|
||||
});
|
||||
|
||||
Some((worktree_id, entry_id))
|
||||
})
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
let directory_id;
|
||||
let new_entry_id = self.resolve_entry(entry_id);
|
||||
if let Some((worktree, expanded_dir_ids)) = self
|
||||
.project
|
||||
.read(cx)
|
||||
.worktree_for_id(worktree_id, cx)
|
||||
.zip(self.expanded_dir_ids.get_mut(&worktree_id))
|
||||
{
|
||||
let directory_id;
|
||||
let new_entry_id = self.resolve_entry(entry_id);
|
||||
if let Some((worktree, expanded_dir_ids)) = self
|
||||
.project
|
||||
.read(cx)
|
||||
.worktree_for_id(worktree_id, cx)
|
||||
.zip(self.expanded_dir_ids.get_mut(&worktree_id))
|
||||
{
|
||||
let worktree = worktree.read(cx);
|
||||
if let Some(mut entry) = worktree.entry_for_id(new_entry_id) {
|
||||
loop {
|
||||
if entry.is_dir() {
|
||||
if let Err(ix) = expanded_dir_ids.binary_search(&entry.id) {
|
||||
expanded_dir_ids.insert(ix, entry.id);
|
||||
}
|
||||
directory_id = entry.id;
|
||||
break;
|
||||
} else {
|
||||
if let Some(parent_path) = entry.path.parent() {
|
||||
if let Some(parent_entry) = worktree.entry_for_path(parent_path) {
|
||||
entry = parent_entry;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return;
|
||||
let worktree = worktree.read(cx);
|
||||
if let Some(mut entry) = worktree.entry_for_id(new_entry_id) {
|
||||
loop {
|
||||
if entry.is_dir() {
|
||||
if let Err(ix) = expanded_dir_ids.binary_search(&entry.id) {
|
||||
expanded_dir_ids.insert(ix, entry.id);
|
||||
}
|
||||
directory_id = entry.id;
|
||||
break;
|
||||
} else {
|
||||
if let Some(parent_path) = entry.path.parent() {
|
||||
if let Some(parent_entry) = worktree.entry_for_path(parent_path) {
|
||||
entry = parent_entry;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
self.marked_entries.clear();
|
||||
self.edit_state = Some(EditState {
|
||||
worktree_id,
|
||||
entry_id: directory_id,
|
||||
leaf_entry_id: None,
|
||||
is_dir,
|
||||
processing_filename: None,
|
||||
previously_focused: self.selection,
|
||||
depth: 0,
|
||||
validation_state: ValidationState::None,
|
||||
});
|
||||
self.filename_editor.update(cx, |editor, cx| {
|
||||
editor.clear(window, cx);
|
||||
window.focus(&editor.focus_handle(cx));
|
||||
});
|
||||
self.update_visible_entries(Some((worktree_id, NEW_ENTRY_ID)), cx);
|
||||
self.autoscroll(cx);
|
||||
cx.notify();
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
self.marked_entries.clear();
|
||||
self.edit_state = Some(EditState {
|
||||
worktree_id,
|
||||
entry_id: directory_id,
|
||||
leaf_entry_id: None,
|
||||
is_dir,
|
||||
processing_filename: None,
|
||||
previously_focused: self.selection,
|
||||
depth: 0,
|
||||
validation_state: ValidationState::None,
|
||||
});
|
||||
self.filename_editor.update(cx, |editor, cx| {
|
||||
editor.clear(window, cx);
|
||||
window.focus(&editor.focus_handle(cx));
|
||||
});
|
||||
self.update_visible_entries(Some((worktree_id, NEW_ENTRY_ID)), cx);
|
||||
self.autoscroll(cx);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn unflatten_entry_id(&self, leaf_entry_id: ProjectEntryId) -> ProjectEntryId {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue