Do not split on only external directories being drag and dropped

This commit is contained in:
Kirill Bulatov 2024-01-11 15:09:43 +02:00
parent 348bc842ef
commit 2e36b0b72a

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());
cx.spawn(|workspace, mut cx| async move {
let mut is_file_checks = FuturesUnordered::new();
for path in &paths {
is_file_checks.push(fs.is_file(path))
}
let mut has_files_to_open = false;
while let Some(is_file) = is_file_checks.next().await {
if is_file {
has_files_to_open = true;
break;
}
}
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 { if let Some(split_direction) = split_direction {
to_pane = workspace.split_pane(to_pane, split_direction, cx); to_pane = workspace.split_pane(to_pane, split_direction, cx);
} }
workspace workspace.open_paths(
.open_paths(
paths, paths,
OpenVisible::OnlyDirectories, OpenVisible::OnlyDirectories,
Some(to_pane.downgrade()), Some(to_pane.downgrade()),
cx, cx,
) )
})
.ok()
{
let _opened_items: Vec<_> = open_task.await;
}
})
.detach(); .detach();
});
}) })
.log_err(); .log_err();
} }