Skip to content

Commit

Permalink
removed_restore_selection
Browse files Browse the repository at this point in the history
  • Loading branch information
0SlowPoke0 committed Jan 13, 2025
1 parent 7e2d510 commit 4e5e8b8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
1 change: 0 additions & 1 deletion editor/src/messages/input_mapper/input_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ pub fn input_mappings() -> Mapping {
entry!(PointerMove; refresh_keys=[Control, Shift], action_dispatch=TransformLayerMessage::PointerMove { slow_key: Shift, snap_key: Control }),
//
// SelectToolMessage
entry!(KeyDown(Shift); refresh_keys=[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
74 changes: 40 additions & 34 deletions editor/src/messages/tool/tool_messages/select_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ struct SelectToolData {
auto_panning: AutoPanning,
previously_selected_layers: Vec<LayerNodeIdentifier>,
previous_selected: bool,
restore_selection_debounce: bool,
shift_pressed_before_drag: bool,
}

impl SelectToolData {
Expand Down Expand Up @@ -652,11 +654,13 @@ impl Fsm for SelectToolFsmState {
else {
tool_data.layers_dragging = selected;
tool_data.previous_selected = true;
tool_data.shift_pressed_before_drag = true;

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

if let Some(intersection) = intersection {
Expand Down Expand Up @@ -822,9 +826,44 @@ impl Fsm for SelectToolFsmState {
SelectToolFsmState::DraggingPivot
}
(SelectToolFsmState::DrawingBox { .. }, SelectToolMessage::PointerMove(modifier_keys)) => {
tool_data.previous_selected = true;
tool_data.drag_current = input.mouse.position;

let selection_set: HashSet<_> = tool_data.previously_selected_layers.iter().collect();

if input.keyboard.key(Key::Shift) && !tool_data.restore_selection_debounce {
log::info!("when shift is pressed:{:?}", tool_data.previous_selected);
tool_data.layers_dragging.extend(&tool_data.previously_selected_layers);
tool_data.previous_selected = false;
tool_data.restore_selection_debounce = true;
}

if !input.keyboard.key(Key::Shift) && tool_data.restore_selection_debounce {
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));
}
if tool_data.shift_pressed_before_drag {
tool_data.layers_dragging.extend(&tool_data.previously_selected_layers);
tool_data.shift_pressed_before_drag = false;
}
tool_data.restore_selection_debounce = false;
}

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();

responses.add(NodeGraphMessage::SelectedNodesSet { nodes: selected_nodes });
responses.add(OverlaysMessage::Draw);

// AutoPanning
Expand Down Expand Up @@ -1105,39 +1144,6 @@ impl Fsm for SelectToolFsmState {

self
}
(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);
tool_data.previous_selected = false;
} else {
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));
}
}

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();

responses.add(NodeGraphMessage::SelectedNodesSet { nodes: selected_nodes });

responses.add(OverlaysMessage::Draw);

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

0 comments on commit 4e5e8b8

Please sign in to comment.