Skip to content

Commit

Permalink
Make Path tool deselect all points on single-click, and select all on…
Browse files Browse the repository at this point in the history
… double-click, of shape's fill (#2148)

* Implement deselect on single-click and select all anchors on double-click

* fixed the single_click_behaviour

* fix flipSmoothSharp when doubleclick and drag

* Cleanup and Clippy fixes

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
  • Loading branch information
0SlowPoke0 and Keavon authored Dec 23, 2024
1 parent a1dc955 commit 77936c4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1655,8 +1655,7 @@ impl DocumentMessageHandler {
/// Finds the artboard that bounds the point in viewport space and be the container of any newly added layers.
pub fn new_layer_bounding_artboard(&self, ipp: &InputPreprocessorMessageHandler) -> LayerNodeIdentifier {
self.click_xray(ipp)
.filter(|layer| self.network_interface.is_artboard(&layer.to_node(), &[]))
.next()
.find(|layer| self.network_interface.is_artboard(&layer.to_node(), &[]))
.unwrap_or(LayerNodeIdentifier::ROOT_PARENT)
}

Expand Down
35 changes: 30 additions & 5 deletions editor/src/messages/tool/tool_messages/path_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ impl PathToolData {
}
self.drag_start_pos = input.mouse.position;
self.previous_mouse_position = document.metadata().document_to_viewport.inverse().transform_point2(input.mouse.position);
shape_editor.select_connected_anchors(document, layer, input.mouse.position);

responses.add(DocumentMessage::StartTransaction);

Expand Down Expand Up @@ -566,6 +565,7 @@ impl Fsm for PathToolFsmState {
) => {
let extend_selection = input.keyboard.get(extend_selection as usize);
let direct_insert_without_sliding = input.keyboard.get(direct_insert_without_sliding as usize);

tool_data.mouse_down(shape_editor, document, input, responses, extend_selection, direct_insert_without_sliding)
}
(
Expand Down Expand Up @@ -606,6 +606,12 @@ impl Fsm for PathToolFsmState {
move_anchor_with_handles,
},
) => {
if tool_data.selection_status.is_none() {
if let Some(layer) = document.click(input) {
shape_editor.select_all_anchors_in_layer(document, layer);
}
}

let anchor_and_handle_toggled = input.keyboard.get(move_anchor_with_handles as usize);
let initial_press = anchor_and_handle_toggled && !tool_data.select_anchor_toggled;
let released_from_toggle = tool_data.select_anchor_toggled && !anchor_and_handle_toggled;
Expand Down Expand Up @@ -749,10 +755,15 @@ impl Fsm for PathToolFsmState {
}
}
}
// Deselect all points if the user clicks the filled region of the shape
else if tool_data.drag_start_pos.distance(input.mouse.position) <= DRAG_THRESHOLD {
shape_editor.deselect_all_points();
}

responses.add(DocumentMessage::EndTransaction);
responses.add(PathToolMessage::SelectedPointUpdated);
tool_data.snap_manager.cleanup(responses);

PathToolFsmState::Ready
}

Expand All @@ -774,11 +785,25 @@ impl Fsm for PathToolFsmState {
PathToolFsmState::Ready
}
(_, PathToolMessage::FlipSmoothSharp) => {
if !tool_data.double_click_handled {
shape_editor.flip_smooth_sharp(&document.network_interface, input.mouse.position, SELECTION_TOLERANCE, responses);
responses.add(PathToolMessage::SelectedPointUpdated);
// Double-clicked on a point
let nearest_point = shape_editor.find_nearest_point_indices(&document.network_interface, input.mouse.position, SELECTION_THRESHOLD);
if nearest_point.is_some() {
// Flip the selected point between smooth and sharp
if !tool_data.double_click_handled && tool_data.drag_start_pos.distance(input.mouse.position) <= DRAG_THRESHOLD {
shape_editor.flip_smooth_sharp(&document.network_interface, input.mouse.position, SELECTION_TOLERANCE, responses);
responses.add(PathToolMessage::SelectedPointUpdated);
}

return PathToolFsmState::Ready;
}
self

// Double-clicked on a filled region
if let Some(layer) = document.click(input) {
// Select all points in the layer
shape_editor.select_connected_anchors(document, layer, input.mouse.position);
}

PathToolFsmState::Ready
}
(_, PathToolMessage::Abort) => {
responses.add(OverlaysMessage::Draw);
Expand Down

0 comments on commit 77936c4

Please sign in to comment.