Select Tool: Deselect selected layer when clicked while holding shift (#1030)

* Change tauri build directory back to `../dist` (#1033)

* Select Tool: Deselect selected layer when clicked while holding shift

* Fix formatting

* Change deselecting to happen on mouse up

* Clean up debug and rustfmt

---------

Co-authored-by: Dennis Kobert <dennis@kobert.dev>
Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Angel Kozlev 2023-02-24 00:47:21 +00:00 committed by Keavon Chambers
parent 8fe19063c1
commit c2234ce3fe
2 changed files with 36 additions and 7 deletions

View File

@ -51,7 +51,7 @@ pub fn default_mapping() -> Mapping {
// SelectToolMessage
entry!(PointerMove; refresh_keys=[Control, Shift, Alt], action_dispatch=SelectToolMessage::PointerMove { axis_align: Shift, snap_angle: Control, center: Alt, duplicate: Alt }),
entry!(KeyDown(Lmb); action_dispatch=SelectToolMessage::DragStart { add_to_selection: Shift }),
entry!(KeyUp(Lmb); action_dispatch=SelectToolMessage::DragStop),
entry!(KeyUp(Lmb); action_dispatch=SelectToolMessage::DragStop { remove_from_selection: Shift }),
entry!(KeyDown(Enter); action_dispatch=SelectToolMessage::Enter),
entry!(DoubleClick; action_dispatch=SelectToolMessage::EditLayer),
entry!(KeyDown(Rmb); action_dispatch=SelectToolMessage::Abort),

View File

@ -54,7 +54,9 @@ pub enum SelectToolMessage {
DragStart {
add_to_selection: Key,
},
DragStop,
DragStop {
remove_from_selection: Key,
},
EditLayer,
Enter,
FlipHorizontal,
@ -255,6 +257,8 @@ struct SelectToolData {
drag_start: ViewportPosition,
drag_current: ViewportPosition,
layers_dragging: Vec<Vec<LayerId>>,
layer_selected_on_start: Option<Vec<LayerId>>,
is_dragging: bool,
not_duplicated_layers: Option<Vec<Vec<LayerId>>>,
drag_box_overlay_layer: Option<Vec<LayerId>>,
path_outlines: PathOutline,
@ -446,6 +450,7 @@ impl Fsm for SelectToolFsmState {
}
if let Some(intersection) = intersection.pop() {
tool_data.layer_selected_on_start = Some(intersection.clone());
selected = vec![intersection];
responses.push_back(DocumentMessage::AddSelectedLayers { additional_layers: selected.clone() }.into());
responses.push_back(DocumentMessage::StartTransaction.into());
@ -465,6 +470,7 @@ impl Fsm for SelectToolFsmState {
state
}
(Dragging, PointerMove { axis_align, duplicate, .. }) => {
tool_data.is_dragging = true;
// TODO: This is a cheat. Break out the relevant functionality from the handler above and call it from there and here.
responses.push_front(SelectToolMessage::DocumentIsDirty.into());
@ -590,7 +596,7 @@ impl Fsm for SelectToolFsmState {
Ready
}
(Dragging, DragStop | Enter) => {
(Dragging, Enter) => {
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
true => DocumentMessage::Undo,
false => DocumentMessage::CommitTransaction,
@ -599,7 +605,30 @@ impl Fsm for SelectToolFsmState {
responses.push_front(response.into());
Ready
}
(ResizingBounds, DragStop | Enter) => {
(Dragging, DragStop { remove_from_selection }) => {
// Deselect layer if not snap dragging
if !tool_data.is_dragging && input.keyboard.get(remove_from_selection as usize) && tool_data.layer_selected_on_start.is_none() {
let quad = tool_data.selection_quad();
let intersection = document.document_legacy.intersects_quad_root(quad, render_data);
if let Some(intersect_layer_path) = intersection.last() {
let replacement_selected_layers = document.selected_layers().filter(|&layer| layer != intersect_layer_path).map(|path| path.to_vec()).collect();
responses.push_back(DocumentMessage::SetSelectedLayers { replacement_selected_layers }.into());
}
}
tool_data.is_dragging = false;
tool_data.layer_selected_on_start = None;
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
true => DocumentMessage::Undo,
false => DocumentMessage::CommitTransaction,
};
tool_data.snap_manager.cleanup(responses);
responses.push_front(response.into());
Ready
}
(ResizingBounds, DragStop { .. } | Enter) => {
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
true => DocumentMessage::Undo,
false => DocumentMessage::CommitTransaction,
@ -614,7 +643,7 @@ impl Fsm for SelectToolFsmState {
Ready
}
(RotatingBounds, DragStop | Enter) => {
(RotatingBounds, DragStop { .. } | Enter) => {
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
true => DocumentMessage::Undo,
false => DocumentMessage::CommitTransaction,
@ -627,7 +656,7 @@ impl Fsm for SelectToolFsmState {
Ready
}
(DraggingPivot, DragStop | Enter) => {
(DraggingPivot, DragStop { .. } | Enter) => {
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
true => DocumentMessage::Undo,
false => DocumentMessage::CommitTransaction,
@ -638,7 +667,7 @@ impl Fsm for SelectToolFsmState {
Ready
}
(DrawingBox, DragStop | Enter) => {
(DrawingBox, DragStop { .. } | Enter) => {
let quad = tool_data.selection_quad();
responses.push_front(
DocumentMessage::AddSelectedLayers {