Skip to content

Commit 5f5e6b8

Browse files
authored
workspace: Fix drag&dropping project panel entries into editor area (#12767)
Fixes #12733 Release Notes: - Fixed drag&dropping project panel entries into editor area & tab bar
1 parent 07dbd2b commit 5f5e6b8

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

crates/project_panel/src/project_panel.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use util::{maybe, NumericPrefixWithSuffix, ResultExt, TryFutureExt};
3636
use workspace::{
3737
dock::{DockPosition, Panel, PanelEvent},
3838
notifications::{DetachAndPromptErr, NotifyTaskExt},
39-
OpenInTerminal, Workspace,
39+
DraggedSelection, OpenInTerminal, SelectedEntry, Workspace,
4040
};
4141
use worktree::CreatedEntry;
4242

@@ -65,26 +65,6 @@ pub struct ProjectPanel {
6565
pending_serialization: Task<Option<()>>,
6666
}
6767

68-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
69-
struct SelectedEntry {
70-
worktree_id: WorktreeId,
71-
entry_id: ProjectEntryId,
72-
}
73-
74-
struct DraggedSelection {
75-
active_selection: SelectedEntry,
76-
marked_selections: Arc<BTreeSet<SelectedEntry>>,
77-
}
78-
79-
impl DraggedSelection {
80-
fn items<'a>(&'a self) -> Box<dyn Iterator<Item = &'a SelectedEntry> + 'a> {
81-
if self.marked_selections.contains(&self.active_selection) {
82-
Box::new(self.marked_selections.iter())
83-
} else {
84-
Box::new(std::iter::once(&self.active_selection))
85-
}
86-
}
87-
}
8868
#[derive(Clone, Debug)]
8969
struct EditState {
9070
worktree_id: WorktreeId,

crates/workspace/src/pane.rs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
SplitDirection, ToggleZoom, Workspace,
1010
};
1111
use anyhow::Result;
12-
use collections::{HashMap, HashSet, VecDeque};
12+
use collections::{BTreeSet, HashMap, HashSet, VecDeque};
1313
use futures::{stream::FuturesUnordered, StreamExt};
1414
use gpui::{
1515
actions, anchored, deferred, impl_actions, prelude::*, Action, AnchorCorner, AnyElement,
@@ -20,7 +20,7 @@ use gpui::{
2020
};
2121
use itertools::Itertools;
2222
use parking_lot::Mutex;
23-
use project::{Project, ProjectEntryId, ProjectPath};
23+
use project::{Project, ProjectEntryId, ProjectPath, WorktreeId};
2424
use serde::Deserialize;
2525
use settings::{Settings, SettingsStore};
2626
use std::{
@@ -43,6 +43,30 @@ use ui::{
4343
use ui::{v_flex, ContextMenu};
4444
use util::{debug_panic, maybe, truncate_and_remove_front, ResultExt};
4545

46+
/// A selected entry in e.g. project panel.
47+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
48+
pub struct SelectedEntry {
49+
pub worktree_id: WorktreeId,
50+
pub entry_id: ProjectEntryId,
51+
}
52+
53+
/// A group of selected entries from project panel.
54+
#[derive(Debug)]
55+
pub struct DraggedSelection {
56+
pub active_selection: SelectedEntry,
57+
pub marked_selections: Arc<BTreeSet<SelectedEntry>>,
58+
}
59+
60+
impl DraggedSelection {
61+
pub fn items<'a>(&'a self) -> Box<dyn Iterator<Item = &'a SelectedEntry> + 'a> {
62+
if self.marked_selections.contains(&self.active_selection) {
63+
Box::new(self.marked_selections.iter())
64+
} else {
65+
Box::new(std::iter::once(&self.active_selection))
66+
}
67+
}
68+
}
69+
4670
#[derive(PartialEq, Clone, Copy, Deserialize, Debug)]
4771
#[serde(rename_all = "camelCase")]
4872
pub enum SaveIntent {
@@ -1602,7 +1626,7 @@ impl Pane {
16021626
.drag_over::<DraggedTab>(|tab, _, cx| {
16031627
tab.bg(cx.theme().colors().drop_target_background)
16041628
})
1605-
.drag_over::<ProjectEntryId>(|tab, _, cx| {
1629+
.drag_over::<DraggedSelection>(|tab, _, cx| {
16061630
tab.bg(cx.theme().colors().drop_target_background)
16071631
})
16081632
.when_some(self.can_drop_predicate.clone(), |this, p| {
@@ -1612,9 +1636,9 @@ impl Pane {
16121636
this.drag_split_direction = None;
16131637
this.handle_tab_drop(dragged_tab, ix, cx)
16141638
}))
1615-
.on_drop(cx.listener(move |this, entry_id: &ProjectEntryId, cx| {
1639+
.on_drop(cx.listener(move |this, selection: &DraggedSelection, cx| {
16161640
this.drag_split_direction = None;
1617-
this.handle_project_entry_drop(entry_id, cx)
1641+
this.handle_project_entry_drop(&selection.active_selection.entry_id, cx)
16181642
}))
16191643
.on_drop(cx.listener(move |this, paths, cx| {
16201644
this.drag_split_direction = None;
@@ -1820,16 +1844,16 @@ impl Pane {
18201844
.drag_over::<DraggedTab>(|bar, _, cx| {
18211845
bar.bg(cx.theme().colors().drop_target_background)
18221846
})
1823-
.drag_over::<ProjectEntryId>(|bar, _, cx| {
1847+
.drag_over::<DraggedSelection>(|bar, _, cx| {
18241848
bar.bg(cx.theme().colors().drop_target_background)
18251849
})
18261850
.on_drop(cx.listener(move |this, dragged_tab: &DraggedTab, cx| {
18271851
this.drag_split_direction = None;
18281852
this.handle_tab_drop(dragged_tab, this.items.len(), cx)
18291853
}))
1830-
.on_drop(cx.listener(move |this, entry_id: &ProjectEntryId, cx| {
1854+
.on_drop(cx.listener(move |this, selection: &DraggedSelection, cx| {
18311855
this.drag_split_direction = None;
1832-
this.handle_project_entry_drop(entry_id, cx)
1856+
this.handle_project_entry_drop(&selection.active_selection.entry_id, cx)
18331857
}))
18341858
.on_drop(cx.listener(move |this, paths, cx| {
18351859
this.drag_split_direction = None;
@@ -2179,7 +2203,7 @@ impl Render for Pane {
21792203
.relative()
21802204
.group("")
21812205
.on_drag_move::<DraggedTab>(cx.listener(Self::handle_drag_move))
2182-
.on_drag_move::<ProjectEntryId>(cx.listener(Self::handle_drag_move))
2206+
.on_drag_move::<DraggedSelection>(cx.listener(Self::handle_drag_move))
21832207
.on_drag_move::<ExternalPaths>(cx.listener(Self::handle_drag_move))
21842208
.map(|div| {
21852209
if let Some(item) = self.active_item() {
@@ -2205,16 +2229,19 @@ impl Render for Pane {
22052229
.absolute()
22062230
.bg(cx.theme().colors().drop_target_background)
22072231
.group_drag_over::<DraggedTab>("", |style| style.visible())
2208-
.group_drag_over::<ProjectEntryId>("", |style| style.visible())
2232+
.group_drag_over::<DraggedSelection>("", |style| style.visible())
22092233
.group_drag_over::<ExternalPaths>("", |style| style.visible())
22102234
.when_some(self.can_drop_predicate.clone(), |this, p| {
22112235
this.can_drop(move |a, cx| p(a, cx))
22122236
})
22132237
.on_drop(cx.listener(move |this, dragged_tab, cx| {
22142238
this.handle_tab_drop(dragged_tab, this.active_item_index(), cx)
22152239
}))
2216-
.on_drop(cx.listener(move |this, entry_id, cx| {
2217-
this.handle_project_entry_drop(entry_id, cx)
2240+
.on_drop(cx.listener(move |this, selection: &DraggedSelection, cx| {
2241+
this.handle_project_entry_drop(
2242+
&selection.active_selection.entry_id,
2243+
cx,
2244+
)
22182245
}))
22192246
.on_drop(cx.listener(move |this, paths, cx| {
22202247
this.handle_external_paths_drop(paths, cx)

0 commit comments

Comments
 (0)