Skip to content

Commit 14a0b3a

Browse files
committed
add DragStartIntent resolution
1 parent a721b8c commit 14a0b3a

1 file changed

Lines changed: 81 additions & 54 deletions

File tree

editor/src/messages/tool/tool_messages/select_tool.rs

Lines changed: 81 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,17 @@ impl Default for SelectToolFsmState {
317317
}
318318
}
319319

320+
#[derive(Debug)]
321+
enum DragStartIntent {
322+
DragPivot,
323+
Resize,
324+
Skew,
325+
DragWithPreviousSelection,
326+
DragWithNewSelection(LayerNodeIdentifier),
327+
Rotate,
328+
Draw,
329+
}
330+
320331
#[derive(Clone, Debug, Default)]
321332
struct SelectToolData {
322333
drag_start: ViewportPosition,
@@ -887,74 +898,82 @@ impl Fsm for SelectToolFsmState {
887898

888899
let show_compass = bounds.is_some_and(|quad| quad.all_sides_at_least_width(COMPASS_ROSE_HOVER_RING_DIAMETER) && quad.contains(mouse_position));
889900
let can_grab_compass_rose = compass_rose_state.can_grab() && (show_compass || bounds.is_none());
901+
let lasso_select = input.keyboard.key(lasso_select_key);
890902

891-
let state = if is_over_pivot
892-
// Dragging the pivot
893-
{
894-
responses.add(DocumentMessage::StartTransaction);
895-
896-
// tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(), true, true);
897-
// tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
898-
899-
SelectToolFsmState::DraggingPivot
900-
}
901-
// Dragging one (or two, forming a corner) of the transform cage bounding box edges
902-
else if resize {
903-
tool_data.get_snap_candidates(document, input);
904-
SelectToolFsmState::ResizingBounds
903+
let drag_start_intent = if is_over_pivot {
904+
DragStartIntent::DragPivot
905+
} else if resize {
906+
DragStartIntent::Resize
905907
} else if skew {
906-
tool_data.get_snap_candidates(document, input);
907-
SelectToolFsmState::SkewingBounds { skew: Key::Control }
908-
}
909-
// Dragging the selected layers around to transform them
910-
else if can_grab_compass_rose || intersection.is_some_and(|intersection| selected.iter().any(|selected_layer| intersection.starts_with(*selected_layer, document.metadata()))) {
911-
responses.add(DocumentMessage::StartTransaction);
908+
DragStartIntent::Skew
909+
} else if rotate {
910+
DragStartIntent::Rotate
911+
} else if lasso_select {
912+
DragStartIntent::Draw
913+
} else if can_grab_compass_rose || intersection.is_some_and(|intersection| selected.iter().any(|selected_layer| intersection.starts_with(*selected_layer, document.metadata()))) {
914+
DragStartIntent::DragWithPreviousSelection
915+
} else if let Some(intersection) = intersection {
916+
DragStartIntent::DragWithNewSelection(intersection)
917+
} else {
918+
DragStartIntent::Draw
919+
};
912920

913-
if input.keyboard.key(select_deepest_key) || tool_data.nested_selection_behavior == NestedSelectionBehavior::Deepest {
914-
tool_data.select_single_layer = intersection;
915-
} else {
916-
tool_data.select_single_layer = intersection.and_then(|intersection| intersection.ancestors(document.metadata()).find(|ancestor| selected.contains(ancestor)));
921+
let state = match drag_start_intent {
922+
DragStartIntent::DragPivot => {
923+
responses.add(DocumentMessage::StartTransaction);
924+
// tool_data.snap_manager.start_snap(document, input, document.bounding_boxes(), true, true);
925+
// tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
926+
927+
SelectToolFsmState::DraggingPivot
917928
}
929+
DragStartIntent::Resize => {
930+
tool_data.get_snap_candidates(document, input);
931+
SelectToolFsmState::ResizingBounds
932+
}
933+
DragStartIntent::Skew => {
934+
tool_data.get_snap_candidates(document, input);
935+
SelectToolFsmState::SkewingBounds { skew: Key::Control }
936+
}
937+
DragStartIntent::DragWithPreviousSelection => {
938+
responses.add(DocumentMessage::StartTransaction);
939+
if input.keyboard.key(select_deepest_key) || tool_data.nested_selection_behavior == NestedSelectionBehavior::Deepest {
940+
tool_data.select_single_layer = intersection;
941+
} else {
942+
tool_data.select_single_layer = intersection.and_then(|intersection| intersection.ancestors(document.metadata()).find(|ancestor| selected.contains(ancestor)));
943+
}
918944

919-
tool_data.layers_dragging = selected;
945+
tool_data.layers_dragging = selected;
920946

921-
tool_data.get_snap_candidates(document, input);
922-
let (axis, using_compass) = {
923-
let axis_state = compass_rose_state.axis_type().filter(|_| can_grab_compass_rose);
924-
(axis_state.unwrap_or_default(), axis_state.is_some())
925-
};
926-
SelectToolFsmState::Dragging {
927-
axis,
928-
using_compass,
929-
has_dragged: false,
930-
deepest: input.keyboard.key(select_deepest_key),
931-
remove: input.keyboard.key(extend_selection),
932-
}
933-
}
934-
// Dragging near the transform cage bounding box to rotate it
935-
else if rotate {
936-
SelectToolFsmState::RotatingBounds
937-
}
938-
// Dragging a selection box or lasso
939-
else {
940-
tool_data.layers_dragging = selected;
941-
let extend = input.keyboard.key(extend_selection);
942-
if !extend && !input.keyboard.key(remove_from_selection) {
943-
responses.add(DocumentMessage::DeselectAllLayers);
944-
tool_data.layers_dragging.clear();
947+
tool_data.get_snap_candidates(document, input);
948+
let (axis, using_compass) = {
949+
let axis_state = compass_rose_state.axis_type().filter(|_| can_grab_compass_rose);
950+
(axis_state.unwrap_or_default(), axis_state.is_some())
951+
};
952+
SelectToolFsmState::Dragging {
953+
axis,
954+
using_compass,
955+
has_dragged: false,
956+
deepest: input.keyboard.key(select_deepest_key),
957+
remove: input.keyboard.key(extend_selection),
958+
}
945959
}
960+
DragStartIntent::Rotate => SelectToolFsmState::RotatingBounds,
961+
DragStartIntent::DragWithNewSelection(layer) => {
962+
tool_data.layers_dragging = selected;
963+
let extend = input.keyboard.key(extend_selection);
964+
if !extend && !input.keyboard.key(remove_from_selection) {
965+
responses.add(DocumentMessage::DeselectAllLayers);
966+
tool_data.layers_dragging.clear();
967+
}
946968

947-
let lasso_select = input.keyboard.key(lasso_select_key);
948-
if !lasso_select && let Some(intersection) = intersection {
949-
tool_data.layer_selected_on_start = Some(intersection);
969+
tool_data.layer_selected_on_start = Some(layer);
950970
selected = intersection_list;
951971

952972
match tool_data.nested_selection_behavior {
953973
NestedSelectionBehavior::Shallowest if !input.keyboard.key(select_deepest_key) => drag_shallowest_manipulation(responses, selected, tool_data, document, false, extend),
954974
_ => drag_deepest_manipulation(responses, selected, tool_data, document, false),
955975
}
956976
tool_data.get_snap_candidates(document, input);
957-
958977
responses.add(DocumentMessage::StartTransaction);
959978
SelectToolFsmState::Dragging {
960979
axis: Axis::None,
@@ -963,7 +982,15 @@ impl Fsm for SelectToolFsmState {
963982
deepest: input.keyboard.key(select_deepest_key),
964983
remove: input.keyboard.key(extend_selection),
965984
}
966-
} else {
985+
}
986+
DragStartIntent::Draw => {
987+
tool_data.layers_dragging = selected;
988+
let extend = input.keyboard.key(extend_selection);
989+
if !extend && !input.keyboard.key(remove_from_selection) {
990+
responses.add(DocumentMessage::DeselectAllLayers);
991+
tool_data.layers_dragging.clear();
992+
}
993+
967994
let selection_shape = if lasso_select { SelectionShapeType::Lasso } else { SelectionShapeType::Box };
968995
SelectToolFsmState::Drawing { selection_shape, has_drawn: false }
969996
}

0 commit comments

Comments
 (0)