Do not split on only external directories being drag and dropped (#4015)

Release Notes:

- Fixed drag and dropped folders opening an empty split pane
This commit is contained in:
Kirill Bulatov 2024-01-11 15:23:53 +02:00 committed by GitHub
commit 4fe0c473ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ use crate::{
}; };
use anyhow::Result; use anyhow::Result;
use collections::{HashMap, HashSet, VecDeque}; use collections::{HashMap, HashSet, VecDeque};
use futures::{stream::FuturesUnordered, StreamExt};
use gpui::{ use gpui::{
actions, impl_actions, overlay, prelude::*, Action, AnchorCorner, AnyElement, AppContext, actions, impl_actions, overlay, prelude::*, Action, AnchorCorner, AnyElement, AppContext,
AsyncWindowContext, DismissEvent, Div, DragMoveEvent, EntityId, EventEmitter, ExternalPaths, AsyncWindowContext, DismissEvent, Div, DragMoveEvent, EntityId, EventEmitter, ExternalPaths,
@ -1796,23 +1797,46 @@ impl Pane {
} }
} }
let mut to_pane = cx.view().clone(); let mut to_pane = cx.view().clone();
let split_direction = self.drag_split_direction; let mut split_direction = self.drag_split_direction;
let paths = paths.paths().to_vec(); let paths = paths.paths().to_vec();
self.workspace self.workspace
.update(cx, |_, cx| { .update(cx, |workspace, cx| {
cx.defer(move |workspace, cx| { let fs = Arc::clone(workspace.project().read(cx).fs());
if let Some(split_direction) = split_direction { cx.spawn(|workspace, mut cx| async move {
to_pane = workspace.split_pane(to_pane, split_direction, cx); let mut is_file_checks = FuturesUnordered::new();
for path in &paths {
is_file_checks.push(fs.is_file(path))
} }
workspace let mut has_files_to_open = false;
.open_paths( while let Some(is_file) = is_file_checks.next().await {
paths, if is_file {
OpenVisible::OnlyDirectories, has_files_to_open = true;
Some(to_pane.downgrade()), break;
cx, }
) }
.detach(); drop(is_file_checks);
}); if !has_files_to_open {
split_direction = None;
}
if let Some(open_task) = workspace
.update(&mut cx, |workspace, cx| {
if let Some(split_direction) = split_direction {
to_pane = workspace.split_pane(to_pane, split_direction, cx);
}
workspace.open_paths(
paths,
OpenVisible::OnlyDirectories,
Some(to_pane.downgrade()),
cx,
)
})
.ok()
{
let _opened_items: Vec<_> = open_task.await;
}
})
.detach();
}) })
.log_err(); .log_err();
} }