Skip to content

Commit

Permalink
added previous_selected_flag to check
Browse files Browse the repository at this point in the history
  • Loading branch information
0SlowPoke0 committed Jan 1, 2025
1 parent a86f01b commit cb2d41d
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions editor/src/messages/tool/tool_messages/select_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl ToolTransition for SelectTool {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
enum SelectToolFsmState {
Ready { selection: NestedSelectionBehavior },
DrawingBox { selection: NestedSelectionBehavior },
DrawingBox { selection: NestedSelectionBehavior, previous_selected: bool },
Dragging,
ResizingBounds,
RotatingBounds,
Expand Down Expand Up @@ -282,7 +282,6 @@ struct SelectToolData {
selected_layers_changed: bool,
snap_candidates: Vec<SnapCandidatePoint>,
auto_panning: AutoPanning,
previously_selected_layers: Vec<LayerNodeIdentifier>,
}

impl SelectToolData {
Expand Down Expand Up @@ -550,7 +549,6 @@ 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 @@ -650,10 +648,12 @@ impl Fsm for SelectToolFsmState {
// Dragging a selection box
else {
tool_data.layers_dragging = selected;
let mut previous_selected = true;

if !input.keyboard.key(extend_selection) {
responses.add(DocumentMessage::DeselectAllLayers);
tool_data.layers_dragging.clear();
previous_selected = false
}

if let Some(intersection) = intersection {
Expand All @@ -666,14 +666,14 @@ impl Fsm for SelectToolFsmState {
}
tool_data.get_snap_candidates(document, input);

responses.add(DocumentMessage::StartTransaction);
SelectToolFsmState::Dragging
} else {
// Make a box selection, preserving previously selected layers
let selection = tool_data.nested_selection_behavior;
SelectToolFsmState::DrawingBox { selection }
}
};
responses.add(DocumentMessage::StartTransaction);
SelectToolFsmState::Dragging
} else {
// Make a box selection, preserving previously selected layers
let selection = tool_data.nested_selection_behavior;
SelectToolFsmState::DrawingBox { selection, previous_selected }
}
};
tool_data.non_duplicated_layers = None;

state
Expand Down Expand Up @@ -818,7 +818,7 @@ impl Fsm for SelectToolFsmState {

SelectToolFsmState::DraggingPivot
}
(SelectToolFsmState::DrawingBox { .. }, SelectToolMessage::PointerMove(modifier_keys)) => {
(SelectToolFsmState::DrawingBox { selection: _, previous_selected }, SelectToolMessage::PointerMove(modifier_keys)) => {
tool_data.drag_current = input.mouse.position;
responses.add(OverlaysMessage::Draw);

Expand All @@ -830,7 +830,7 @@ impl Fsm for SelectToolFsmState {
tool_data.auto_panning.setup_by_mouse_position(input, &messages, responses);

let selection = tool_data.nested_selection_behavior;
SelectToolFsmState::DrawingBox { selection }
SelectToolFsmState::DrawingBox { selection, previous_selected }
}
(SelectToolFsmState::Ready { .. }, SelectToolMessage::PointerMove(_)) => {
let mut cursor = tool_data.bounding_box_manager.as_ref().map_or(MouseCursorIcon::Default, |bounds| bounds.get_cursor(input, true));
Expand Down Expand Up @@ -1100,13 +1100,18 @@ 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 {
(SelectToolFsmState::DrawingBox { selection, previous_selected }, SelectToolMessage::RestoreSelection) => {
// Toggle the selection state based on the previous_selected flag
if previous_selected {
let selection_set: HashSet<_> = tool_data.previously_selected_layers.iter().cloned().collect();
tool_data.layers_dragging.retain(|layer| !selection_set.contains(layer));
} else {
tool_data.layers_dragging.extend(tool_data.previously_selected_layers.clone());
}

// Update the previous_selected flag
let new_previous_selected = !previous_selected;

let selected_nodes: Vec<_> = tool_data
.layers_dragging
.iter()
Expand All @@ -1120,13 +1125,14 @@ impl Fsm for SelectToolFsmState {
})
.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
SelectToolFsmState::DrawingBox {
selection,
previous_selected: new_previous_selected,
}
}
_ => self,
}
Expand Down

0 comments on commit cb2d41d

Please sign in to comment.