Some terminal bugs (#3767)

Fixes:
 - drag and drop into terminal element does not change its style
 - drag and drop terminal tab into main pane then back panics
 - can drop non-terminal items into the terminal pane

Release Notes:

- N/A
This commit is contained in:
Julia
2023-12-21 18:05:14 -05:00
committed by GitHub
4 changed files with 87 additions and 26 deletions
+20 -4
View File
@@ -181,7 +181,7 @@ pub struct Pane {
workspace: WeakView<Workspace>,
project: Model<Project>,
drag_split_direction: Option<SplitDirection>,
// can_drop: Rc<dyn Fn(&DragAndDrop<Workspace>, &WindowContext) -> bool>,
can_drop_predicate: Option<Arc<dyn Fn(&dyn Any, &mut WindowContext) -> bool>>,
can_split: bool,
// render_tab_bar_buttons: Rc<dyn Fn(&mut Pane, &mut ViewContext<Pane>) -> AnyElement<Pane>>,
_subscriptions: Vec<Subscription>,
@@ -229,7 +229,7 @@ pub struct NavigationEntry {
}
#[derive(Clone)]
struct DraggedTab {
pub struct DraggedTab {
pub pane: View<Pane>,
pub ix: usize,
pub item_id: EntityId,
@@ -325,6 +325,7 @@ impl Pane {
workspace: WeakView<Workspace>,
project: Model<Project>,
next_timestamp: Arc<AtomicUsize>,
can_drop_predicate: Option<Arc<dyn Fn(&dyn Any, &mut WindowContext) -> bool + 'static>>,
cx: &mut ViewContext<Self>,
) -> Self {
// todo!("context menu")
@@ -371,7 +372,7 @@ impl Pane {
// tab_context_menu: cx.build_view(|_| ContextMenu::new(pane_view_id, cx)),
workspace,
project,
// can_drop: Rc::new(|_, _| true),
can_drop_predicate,
can_split: true,
// render_tab_bar_buttons: Rc::new(move |pane, cx| {
// Flex::row()
@@ -746,6 +747,10 @@ impl Pane {
.position(|i| i.item_id() == item.item_id())
}
pub fn item_for_index(&self, ix: usize) -> Option<&dyn ItemHandle> {
self.items.get(ix).map(|i| i.as_ref())
}
pub fn toggle_zoom(&mut self, _: &ToggleZoom, cx: &mut ViewContext<Self>) {
if self.zoomed {
cx.emit(Event::ZoomOut);
@@ -1530,6 +1535,9 @@ impl Pane {
)
.drag_over::<DraggedTab>(|tab| tab.bg(cx.theme().colors().drop_target_background))
.drag_over::<ProjectEntryId>(|tab| tab.bg(cx.theme().colors().drop_target_background))
.when_some(self.can_drop_predicate.clone(), |this, p| {
this.can_drop(move |a, cx| p(a, cx))
})
.on_drop(cx.listener(move |this, dragged_tab: &DraggedTab, cx| {
this.drag_split_direction = None;
this.handle_tab_drop(dragged_tab, ix, cx)
@@ -1754,6 +1762,10 @@ impl Pane {
}
fn handle_drag_move<T>(&mut self, event: &DragMoveEvent<T>, cx: &mut ViewContext<Self>) {
if !self.can_split {
return;
}
let edge_width = cx.rem_size() * 8;
let cursor = event.event.position;
let direction = if cursor.x < event.bounds.left() + edge_width {
@@ -1767,9 +1779,9 @@ impl Pane {
} else {
None
};
if direction != self.drag_split_direction {
self.drag_split_direction = direction;
cx.notify();
}
}
@@ -1934,6 +1946,7 @@ impl Render for Pane {
.child(
// drag target
div()
.z_index(1)
.invisible()
.absolute()
.bg(theme::color_alpha(
@@ -1942,6 +1955,9 @@ impl Render for Pane {
))
.group_drag_over::<DraggedTab>("", |style| style.visible())
.group_drag_over::<ProjectEntryId>("", |style| style.visible())
.when_some(self.can_drop_predicate.clone(), |this, p| {
this.can_drop(move |a, cx| p(a, cx))
})
.on_drop(cx.listener(move |this, dragged_tab, cx| {
this.handle_tab_drop(dragged_tab, this.active_item_index(), cx)
}))
+2
View File
@@ -542,6 +542,7 @@ impl Workspace {
weak_handle.clone(),
project.clone(),
pane_history_timestamp.clone(),
None,
cx,
)
});
@@ -1724,6 +1725,7 @@ impl Workspace {
self.weak_handle(),
self.project.clone(),
self.pane_history_timestamp.clone(),
None,
cx,
)
});