Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-select Deselected Layers with Shift During Drawing Box #2171

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!(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
61 changes: 50 additions & 11 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 All @@ -249,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 @@ -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 @@ -646,10 +650,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 @@ -662,14 +668,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 @@ -814,7 +820,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 @@ -826,7 +832,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 @@ -1096,6 +1102,39 @@ impl Fsm for SelectToolFsmState {

self
}
(SelectToolFsmState::DrawingBox { selection, mut previous_selected }, 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;
} else {
if 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, previous_selected }
}
_ => self,
}
}
Expand Down
Loading