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:
parent
8fe19063c1
commit
c2234ce3fe
|
|
@ -51,7 +51,7 @@ pub fn default_mapping() -> Mapping {
|
||||||
// SelectToolMessage
|
// SelectToolMessage
|
||||||
entry!(PointerMove; refresh_keys=[Control, Shift, Alt], action_dispatch=SelectToolMessage::PointerMove { axis_align: Shift, snap_angle: Control, center: Alt, duplicate: Alt }),
|
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!(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!(KeyDown(Enter); action_dispatch=SelectToolMessage::Enter),
|
||||||
entry!(DoubleClick; action_dispatch=SelectToolMessage::EditLayer),
|
entry!(DoubleClick; action_dispatch=SelectToolMessage::EditLayer),
|
||||||
entry!(KeyDown(Rmb); action_dispatch=SelectToolMessage::Abort),
|
entry!(KeyDown(Rmb); action_dispatch=SelectToolMessage::Abort),
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,9 @@ pub enum SelectToolMessage {
|
||||||
DragStart {
|
DragStart {
|
||||||
add_to_selection: Key,
|
add_to_selection: Key,
|
||||||
},
|
},
|
||||||
DragStop,
|
DragStop {
|
||||||
|
remove_from_selection: Key,
|
||||||
|
},
|
||||||
EditLayer,
|
EditLayer,
|
||||||
Enter,
|
Enter,
|
||||||
FlipHorizontal,
|
FlipHorizontal,
|
||||||
|
|
@ -255,6 +257,8 @@ struct SelectToolData {
|
||||||
drag_start: ViewportPosition,
|
drag_start: ViewportPosition,
|
||||||
drag_current: ViewportPosition,
|
drag_current: ViewportPosition,
|
||||||
layers_dragging: Vec<Vec<LayerId>>,
|
layers_dragging: Vec<Vec<LayerId>>,
|
||||||
|
layer_selected_on_start: Option<Vec<LayerId>>,
|
||||||
|
is_dragging: bool,
|
||||||
not_duplicated_layers: Option<Vec<Vec<LayerId>>>,
|
not_duplicated_layers: Option<Vec<Vec<LayerId>>>,
|
||||||
drag_box_overlay_layer: Option<Vec<LayerId>>,
|
drag_box_overlay_layer: Option<Vec<LayerId>>,
|
||||||
path_outlines: PathOutline,
|
path_outlines: PathOutline,
|
||||||
|
|
@ -446,6 +450,7 @@ impl Fsm for SelectToolFsmState {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(intersection) = intersection.pop() {
|
if let Some(intersection) = intersection.pop() {
|
||||||
|
tool_data.layer_selected_on_start = Some(intersection.clone());
|
||||||
selected = vec![intersection];
|
selected = vec![intersection];
|
||||||
responses.push_back(DocumentMessage::AddSelectedLayers { additional_layers: selected.clone() }.into());
|
responses.push_back(DocumentMessage::AddSelectedLayers { additional_layers: selected.clone() }.into());
|
||||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||||
|
|
@ -465,6 +470,7 @@ impl Fsm for SelectToolFsmState {
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
(Dragging, PointerMove { axis_align, duplicate, .. }) => {
|
(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.
|
// 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());
|
responses.push_front(SelectToolMessage::DocumentIsDirty.into());
|
||||||
|
|
||||||
|
|
@ -590,7 +596,7 @@ impl Fsm for SelectToolFsmState {
|
||||||
|
|
||||||
Ready
|
Ready
|
||||||
}
|
}
|
||||||
(Dragging, DragStop | Enter) => {
|
(Dragging, Enter) => {
|
||||||
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
|
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
|
||||||
true => DocumentMessage::Undo,
|
true => DocumentMessage::Undo,
|
||||||
false => DocumentMessage::CommitTransaction,
|
false => DocumentMessage::CommitTransaction,
|
||||||
|
|
@ -599,7 +605,30 @@ impl Fsm for SelectToolFsmState {
|
||||||
responses.push_front(response.into());
|
responses.push_front(response.into());
|
||||||
Ready
|
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 {
|
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
|
||||||
true => DocumentMessage::Undo,
|
true => DocumentMessage::Undo,
|
||||||
false => DocumentMessage::CommitTransaction,
|
false => DocumentMessage::CommitTransaction,
|
||||||
|
|
@ -614,7 +643,7 @@ impl Fsm for SelectToolFsmState {
|
||||||
|
|
||||||
Ready
|
Ready
|
||||||
}
|
}
|
||||||
(RotatingBounds, DragStop | Enter) => {
|
(RotatingBounds, DragStop { .. } | Enter) => {
|
||||||
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
|
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
|
||||||
true => DocumentMessage::Undo,
|
true => DocumentMessage::Undo,
|
||||||
false => DocumentMessage::CommitTransaction,
|
false => DocumentMessage::CommitTransaction,
|
||||||
|
|
@ -627,7 +656,7 @@ impl Fsm for SelectToolFsmState {
|
||||||
|
|
||||||
Ready
|
Ready
|
||||||
}
|
}
|
||||||
(DraggingPivot, DragStop | Enter) => {
|
(DraggingPivot, DragStop { .. } | Enter) => {
|
||||||
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
|
let response = match input.mouse.position.distance(tool_data.drag_start) < 10. * f64::EPSILON {
|
||||||
true => DocumentMessage::Undo,
|
true => DocumentMessage::Undo,
|
||||||
false => DocumentMessage::CommitTransaction,
|
false => DocumentMessage::CommitTransaction,
|
||||||
|
|
@ -638,7 +667,7 @@ impl Fsm for SelectToolFsmState {
|
||||||
|
|
||||||
Ready
|
Ready
|
||||||
}
|
}
|
||||||
(DrawingBox, DragStop | Enter) => {
|
(DrawingBox, DragStop { .. } | Enter) => {
|
||||||
let quad = tool_data.selection_quad();
|
let quad = tool_data.selection_quad();
|
||||||
responses.push_front(
|
responses.push_front(
|
||||||
DocumentMessage::AddSelectedLayers {
|
DocumentMessage::AddSelectedLayers {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue