From d7b8a189e49a1a4bb634676a2821af83cfc6ecd6 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Sat, 22 Oct 2022 11:41:37 -0700 Subject: [PATCH] fix issue where empty pane is created --- crates/gpui/src/presenter.rs | 4 ++-- crates/workspace/src/pane.rs | 27 +++++++++++++++++---------- crates/workspace/src/workspace.rs | 15 ++++++--------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index 16ea5da642..b04dde7e06 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -391,7 +391,7 @@ impl Presenter { //Ensure that hover entrance events aren't sent twice if self.hovered_region_ids.insert(region.id()) { valid_regions.push(region.clone()); - if region.notify_on_hover { + if region.notify_on_hover || region.notify_on_move { notified_views.insert(region.id().view_id()); } } @@ -399,7 +399,7 @@ impl Presenter { // Ensure that hover exit events aren't sent twice if self.hovered_region_ids.remove(®ion.id()) { valid_regions.push(region.clone()); - if region.notify_on_hover { + if region.notify_on_hover || region.notify_on_move { notified_views.insert(region.id().view_id()); } } diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 9f103946bf..1d50a846b4 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1373,6 +1373,7 @@ impl Pane { .and_then(|margin| Self::drop_split_direction(event.position, event.region, margin)) { cx.dispatch_action(SplitWithItem { + from: dragged_item.pane.clone(), item_id_to_move: dragged_item.item.id(), pane_to_split: pane.clone(), split_direction, @@ -1476,9 +1477,13 @@ impl View for Pane { cx, |state, cx| { let overlay_color = Self::tab_overlay_color(true, cx); + // Hovered will cause a render when the mouse enters regardless + // of if mouse position was accessed before + let hovered = state.hovered(); let drag_position = cx .global::>() .currently_dragged::(cx.window_id()) + .filter(|_| hovered) .map(|_| state.mouse_position()); Stack::new() @@ -1498,25 +1503,27 @@ impl View for Pane { ) .with_children(drag_position.map(|drag_position| { Canvas::new(move |region, _, cx| { - let overlay_region = - if let Some(split_direction) = + if region.contains_point(drag_position) { + let overlay_region = if let Some( + split_direction, + ) = Self::drop_split_direction( drag_position, region, 100., /* Replace with theme value */ - ) - { + ) { split_direction.along_edge(region, 100.) } else { region }; - cx.scene.push_quad(Quad { - bounds: overlay_region, - background: overlay_color, - border: Default::default(), - corner_radius: 0., - }); + cx.scene.push_quad(Quad { + bounds: overlay_region, + background: overlay_color, + border: Default::default(), + corner_radius: 0., + }); + } }) .boxed() })) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 512ca23950..4263f83ef1 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -127,6 +127,7 @@ pub struct OpenSharedScreen { } pub struct SplitWithItem { + from: WeakViewHandle, pane_to_split: WeakViewHandle, split_direction: SplitDirection, item_id_to_move: usize, @@ -216,12 +217,14 @@ pub fn init(app_state: Arc, cx: &mut MutableAppContext) { cx.add_action( |workspace: &mut Workspace, SplitWithItem { + from, pane_to_split, item_id_to_move, split_direction, }: &_, cx| { workspace.split_pane_with_item( + from.clone(), pane_to_split.clone(), *item_id_to_move, *split_direction, @@ -1975,26 +1978,20 @@ impl Workspace { pub fn split_pane_with_item( &mut self, + from: WeakViewHandle, pane_to_split: WeakViewHandle, item_id_to_move: usize, split_direction: SplitDirection, cx: &mut ViewContext, ) { - if let Some(pane_to_split) = pane_to_split.upgrade(cx) { + if let Some((pane_to_split, from)) = pane_to_split.upgrade(cx).zip(from.upgrade(cx)) { if &pane_to_split == self.dock_pane() { warn!("Can't split dock pane."); return; } let new_pane = self.add_pane(cx); - Pane::move_item( - self, - pane_to_split.clone(), - new_pane.clone(), - item_id_to_move, - 0, - cx, - ); + Pane::move_item(self, from.clone(), new_pane.clone(), item_id_to_move, 0, cx); self.center .split(&pane_to_split, &new_pane, split_direction) .unwrap();