project_panel: Double-click on blank space in project panel to create a new file (#15353)

Similar feature implemented in VSCode.


https://github.com/user-attachments/assets/ae250b5f-283c-4211-8947-d5d5703eb2d0


Release Notes:

- Added double-click to create a new file when clicking on blank space
in the project panel.
This commit is contained in:
Suhun Han 2024-07-30 00:33:13 +09:00 committed by GitHub
parent b8f20053d8
commit f124ca6474
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2144,6 +2144,8 @@ impl ProjectPanel {
return;
}
if !show_editor {
cx.stop_propagation();
if let Some(selection) =
this.selection.filter(|_| event.down.modifiers.shift)
{
@ -2437,6 +2439,28 @@ impl Render for ProjectPanel {
.on_action(cx.listener(Self::copy))
.on_action(cx.listener(Self::paste))
.on_action(cx.listener(Self::duplicate))
.on_click(cx.listener(|this, event: &gpui::ClickEvent, cx| {
if event.up.click_count > 1 {
if let Some(entry_id) = this.last_worktree_root_id {
let project = this.project.read(cx);
let worktree_id = if let Some(worktree) =
project.worktree_for_entry(entry_id, cx)
{
worktree.read(cx).id()
} else {
return;
};
this.selection = Some(SelectedEntry {
worktree_id,
entry_id,
});
this.new_file(&NewFile, cx);
}
}
}))
})
.when(project.is_local(), |el| {
el.on_action(cx.listener(Self::reveal_in_finder))