fix: persist selected action on entity change

This commit is contained in:
Ashley Wulber 2024-06-12 14:45:57 -04:00 committed by Ashley Wulber
parent 98231fa99a
commit d2b3531984

View file

@ -698,21 +698,23 @@ where
}) })
.find(|(_key, bounds)| bounds.contains(Point::new(*x as f32, *y as f32))) .find(|(_key, bounds)| bounds.contains(Point::new(*x as f32, *y as f32)))
.map(|(key, _)| key); .map(|(key, _)| key);
if let Some(entity) = entity {
let on_dnd_enter = self let on_dnd_enter =
.on_dnd_enter self.on_dnd_enter
.as_ref() .as_ref()
.map(|on_enter| |_, _, mime_types| on_enter(entity, mime_types)); .zip(entity.clone())
.map(|(on_enter, entity)| {
move |_, _, mime_types| on_enter(entity, mime_types)
});
_ = state.dnd_state.on_enter::<Message>( _ = state.dnd_state.on_enter::<Message>(
*x, *x,
*y, *y,
mime_types.clone(), mime_types.clone(),
on_dnd_enter, on_dnd_enter,
Some(entity), entity,
); );
} }
}
DndEvent::Offer(id, OfferEvent::Leave | OfferEvent::LeaveDestination) DndEvent::Offer(id, OfferEvent::Leave | OfferEvent::LeaveDestination)
if Some(my_id) == *id => if Some(my_id) == *id =>
{ {
@ -741,11 +743,19 @@ where
Some(new_entity), Some(new_entity),
); );
if Some(Some(new_entity)) != entity { if Some(Some(new_entity)) != entity {
let prev_action = state
.dnd_state
.drag_offer
.as_ref()
.map(|dnd| dnd.selected_action);
if let Some(on_dnd_enter) = self.on_dnd_enter.as_ref() { if let Some(on_dnd_enter) = self.on_dnd_enter.as_ref() {
shell.publish(on_dnd_enter(new_entity, Vec::new())); shell.publish(on_dnd_enter(new_entity, Vec::new()));
} }
if let Some(dnd) = state.dnd_state.drag_offer.as_mut() { if let Some(dnd) = state.dnd_state.drag_offer.as_mut() {
dnd.data = Some(new_entity); dnd.data = Some(new_entity);
if let Some(prev_action) = prev_action {
dnd.selected_action = prev_action;
}
} }
} }
} else if entity.is_some() { } else if entity.is_some() {
@ -769,7 +779,7 @@ where
.on_drop::<Message>(None::<fn(_, _) -> Message>); .on_drop::<Message>(None::<fn(_, _) -> Message>);
} }
DndEvent::Offer(id, OfferEvent::SelectedAction(action)) if Some(my_id) == *id => { DndEvent::Offer(id, OfferEvent::SelectedAction(action)) if Some(my_id) == *id => {
if entity.is_some() { if state.dnd_state.drag_offer.is_some() {
_ = state _ = state
.dnd_state .dnd_state
.on_action_selected::<Message>(*action, None::<fn(_) -> Message>); .on_action_selected::<Message>(*action, None::<fn(_) -> Message>);