fix issue where empty pane is created

This commit is contained in:
K Simmons 2022-10-22 11:41:37 -07:00
parent cfde3e348c
commit d7b8a189e4
3 changed files with 25 additions and 21 deletions

View file

@ -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(&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());
}
}

View file

@ -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::<DragAndDrop<Workspace>>()
.currently_dragged::<DraggedItem>(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()
}))

View file

@ -127,6 +127,7 @@ pub struct OpenSharedScreen {
}
pub struct SplitWithItem {
from: WeakViewHandle<Pane>,
pane_to_split: WeakViewHandle<Pane>,
split_direction: SplitDirection,
item_id_to_move: usize,
@ -216,12 +217,14 @@ pub fn init(app_state: Arc<AppState>, 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>,
pane_to_split: WeakViewHandle<Pane>,
item_id_to_move: usize,
split_direction: SplitDirection,
cx: &mut ViewContext<Self>,
) {
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();