Skip to content

Commit

Permalink
implement restore selection before drag
Browse files Browse the repository at this point in the history
  • Loading branch information
0SlowPoke0 committed Jan 1, 2025
1 parent f225756 commit a86f01b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions editor/src/messages/input_mapper/input_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub fn input_mappings() -> Mapping {
entry!(PointerMove; refresh_keys=[Control, Shift], action_dispatch=TransformLayerMessage::PointerMove { slow_key: Shift, snap_key: Control }),
//
// SelectToolMessage
entry!(KeyDownNoRepeat(Shift); action_dispatch=SelectToolMessage::RestoreSelection),
entry!(PointerMove; refresh_keys=[Control, Alt, Shift], action_dispatch=SelectToolMessage::PointerMove(SelectToolPointerKeys { axis_align: Shift, snap_angle: Control, center: Alt, duplicate: Alt })),
entry!(KeyDown(MouseLeft); action_dispatch=SelectToolMessage::DragStart { extend_selection: Shift, select_deepest: Accel }),
entry!(KeyUp(MouseLeft); action_dispatch=SelectToolMessage::DragStop { remove_from_selection: Shift, negative_box_selection: Control }),
Expand Down
32 changes: 32 additions & 0 deletions editor/src/messages/tool/tool_messages/select_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub enum SelectToolMessage {
PointerOutsideViewport(SelectToolPointerKeys),
SelectOptions(SelectOptionsUpdate),
SetPivot { position: PivotPosition },
RestoreSelection,
}

impl ToolMetadata for SelectTool {
Expand Down Expand Up @@ -229,6 +230,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for SelectT

let additional = match self.fsm_state {
SelectToolFsmState::Ready { .. } => actions!(SelectToolMessageDiscriminant; DragStart),
SelectToolFsmState::DrawingBox { .. } => actions!(SelectToolMessageDiscriminant;RestoreSelection,DragStop),
_ => actions!(SelectToolMessageDiscriminant; DragStop),
};
common.extend(additional);
Expand Down Expand Up @@ -280,6 +282,7 @@ struct SelectToolData {
selected_layers_changed: bool,
snap_candidates: Vec<SnapCandidatePoint>,
auto_panning: AutoPanning,
previously_selected_layers: Vec<LayerNodeIdentifier>,
}

impl SelectToolData {
Expand Down Expand Up @@ -547,6 +550,7 @@ impl Fsm for SelectToolFsmState {
.collect();
let intersection_list = document.click_list(input).collect::<Vec<_>>();
let intersection = document.find_deepest(&intersection_list);
tool_data.previously_selected_layers = selected.clone();

// If the user is dragging the bounding box bounds, go into ResizingBounds mode.
// If the user is dragging the rotate trigger, go into RotatingBounds mode.
Expand Down Expand Up @@ -1096,6 +1100,34 @@ impl Fsm for SelectToolFsmState {

self
}
(SelectToolFsmState::DrawingBox { .. }, SelectToolMessage::RestoreSelection) => {
if !tool_data.previously_selected_layers.iter().any(|item| tool_data.layers_dragging.contains(item)) {
tool_data.layers_dragging.extend(tool_data.previously_selected_layers.clone());
} else {
let selection_set: HashSet<_> = tool_data.previously_selected_layers.iter().cloned().collect();
tool_data.layers_dragging.retain(|layer| !selection_set.contains(layer));
}
let selected_nodes: Vec<_> = tool_data
.layers_dragging
.iter()
.filter_map(|layer| {
if *layer != LayerNodeIdentifier::ROOT_PARENT {
Some(layer.to_node())
} else {
log::error!("ROOT_PARENT found in tool_data.layers_dragging during selection set");
None
}
})
.collect();

// Dispatch the SelectedNodesSet message
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: selected_nodes });

// Dispatch the OverlaysMessage::Draw message to update the UI
responses.add(OverlaysMessage::Draw);

self
}
_ => self,
}
}
Expand Down

0 comments on commit a86f01b

Please sign in to comment.