Skip to content

Commit

Permalink
minor improvments and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0SlowPoke0 authored and Keavon committed Jan 10, 2025
1 parent 7f40fad commit 2981512
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions editor/src/messages/tool/tool_messages/select_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl ToolTransition for SelectTool {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
enum SelectToolFsmState {
Ready { selection: NestedSelectionBehavior },
DrawingBox { selection: NestedSelectionBehavior, previous_selected: bool },
DrawingBox { selection: NestedSelectionBehavior },
Dragging,
ResizingBounds,
RotatingBounds,
Expand Down Expand Up @@ -284,6 +284,7 @@ struct SelectToolData {
snap_candidates: Vec<SnapCandidatePoint>,
auto_panning: AutoPanning,
previously_selected_layers: Vec<LayerNodeIdentifier>,
previous_selected: bool,
}

impl SelectToolData {
Expand Down Expand Up @@ -660,12 +661,12 @@ impl Fsm for SelectToolFsmState {
// Dragging a selection box
else {
tool_data.layers_dragging = selected;
let mut previous_selected = true;
tool_data.previous_selected = true;

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

if let Some(intersection) = intersection {
Expand All @@ -683,7 +684,7 @@ impl Fsm for SelectToolFsmState {
} else {
// Make a box selection, preserving previously selected layers
let selection = tool_data.nested_selection_behavior;
SelectToolFsmState::DrawingBox { selection, previous_selected }
SelectToolFsmState::DrawingBox { selection }
}
};
tool_data.non_duplicated_layers = None;
Expand Down Expand Up @@ -830,8 +831,10 @@ impl Fsm for SelectToolFsmState {

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

responses.add(OverlaysMessage::Draw);

// AutoPanning
Expand All @@ -842,7 +845,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, previous_selected }
SelectToolFsmState::DrawingBox { selection }
}
(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 @@ -1112,14 +1115,14 @@ impl Fsm for SelectToolFsmState {

self
}
(SelectToolFsmState::DrawingBox { selection, mut previous_selected }, SelectToolMessage::RestoreSelection) => {
(SelectToolFsmState::DrawingBox { selection }, SelectToolMessage::RestoreSelection) => {
let selection_set: HashSet<_> = tool_data.previously_selected_layers.iter().collect();

if input.keyboard.key(Key::Shift) {
tool_data.layers_dragging.extend(&tool_data.previously_selected_layers);
previous_selected = false;
tool_data.previous_selected = false;
} else {
if previous_selected {
if tool_data.previous_selected {
tool_data.layers_dragging.extend(&tool_data.previously_selected_layers);
} else {
tool_data.layers_dragging.retain(|layer| !selection_set.contains(layer));
Expand All @@ -1143,7 +1146,7 @@ impl Fsm for SelectToolFsmState {

responses.add(OverlaysMessage::Draw);

SelectToolFsmState::DrawingBox { selection, previous_selected }
SelectToolFsmState::DrawingBox { selection }
}
_ => self,
}
Expand Down

0 comments on commit 2981512

Please sign in to comment.