Skip to content

Commit 77936c4

Browse files
0SlowPoke0Keavon
andauthored
Make Path tool deselect all points on single-click, and select all on 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 <[email protected]>
1 parent a1dc955 commit 77936c4

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,8 +1655,7 @@ impl DocumentMessageHandler {
16551655
/// Finds the artboard that bounds the point in viewport space and be the container of any newly added layers.
16561656
pub fn new_layer_bounding_artboard(&self, ipp: &InputPreprocessorMessageHandler) -> LayerNodeIdentifier {
16571657
self.click_xray(ipp)
1658-
.filter(|layer| self.network_interface.is_artboard(&layer.to_node(), &[]))
1659-
.next()
1658+
.find(|layer| self.network_interface.is_artboard(&layer.to_node(), &[]))
16601659
.unwrap_or(LayerNodeIdentifier::ROOT_PARENT)
16611660
}
16621661

editor/src/messages/tool/tool_messages/path_tool.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ impl PathToolData {
397397
}
398398
self.drag_start_pos = input.mouse.position;
399399
self.previous_mouse_position = document.metadata().document_to_viewport.inverse().transform_point2(input.mouse.position);
400-
shape_editor.select_connected_anchors(document, layer, input.mouse.position);
401400

402401
responses.add(DocumentMessage::StartTransaction);
403402

@@ -566,6 +565,7 @@ impl Fsm for PathToolFsmState {
566565
) => {
567566
let extend_selection = input.keyboard.get(extend_selection as usize);
568567
let direct_insert_without_sliding = input.keyboard.get(direct_insert_without_sliding as usize);
568+
569569
tool_data.mouse_down(shape_editor, document, input, responses, extend_selection, direct_insert_without_sliding)
570570
}
571571
(
@@ -606,6 +606,12 @@ impl Fsm for PathToolFsmState {
606606
move_anchor_with_handles,
607607
},
608608
) => {
609+
if tool_data.selection_status.is_none() {
610+
if let Some(layer) = document.click(input) {
611+
shape_editor.select_all_anchors_in_layer(document, layer);
612+
}
613+
}
614+
609615
let anchor_and_handle_toggled = input.keyboard.get(move_anchor_with_handles as usize);
610616
let initial_press = anchor_and_handle_toggled && !tool_data.select_anchor_toggled;
611617
let released_from_toggle = tool_data.select_anchor_toggled && !anchor_and_handle_toggled;
@@ -749,10 +755,15 @@ impl Fsm for PathToolFsmState {
749755
}
750756
}
751757
}
758+
// Deselect all points if the user clicks the filled region of the shape
759+
else if tool_data.drag_start_pos.distance(input.mouse.position) <= DRAG_THRESHOLD {
760+
shape_editor.deselect_all_points();
761+
}
752762

753763
responses.add(DocumentMessage::EndTransaction);
754764
responses.add(PathToolMessage::SelectedPointUpdated);
755765
tool_data.snap_manager.cleanup(responses);
766+
756767
PathToolFsmState::Ready
757768
}
758769

@@ -774,11 +785,25 @@ impl Fsm for PathToolFsmState {
774785
PathToolFsmState::Ready
775786
}
776787
(_, PathToolMessage::FlipSmoothSharp) => {
777-
if !tool_data.double_click_handled {
778-
shape_editor.flip_smooth_sharp(&document.network_interface, input.mouse.position, SELECTION_TOLERANCE, responses);
779-
responses.add(PathToolMessage::SelectedPointUpdated);
788+
// Double-clicked on a point
789+
let nearest_point = shape_editor.find_nearest_point_indices(&document.network_interface, input.mouse.position, SELECTION_THRESHOLD);
790+
if nearest_point.is_some() {
791+
// Flip the selected point between smooth and sharp
792+
if !tool_data.double_click_handled && tool_data.drag_start_pos.distance(input.mouse.position) <= DRAG_THRESHOLD {
793+
shape_editor.flip_smooth_sharp(&document.network_interface, input.mouse.position, SELECTION_TOLERANCE, responses);
794+
responses.add(PathToolMessage::SelectedPointUpdated);
795+
}
796+
797+
return PathToolFsmState::Ready;
780798
}
781-
self
799+
800+
// Double-clicked on a filled region
801+
if let Some(layer) = document.click(input) {
802+
// Select all points in the layer
803+
shape_editor.select_connected_anchors(document, layer, input.mouse.position);
804+
}
805+
806+
PathToolFsmState::Ready
782807
}
783808
(_, PathToolMessage::Abort) => {
784809
responses.add(OverlaysMessage::Draw);

0 commit comments

Comments
 (0)