From 77936c44b053a7a4cf5af677e024bb443738cdde Mon Sep 17 00:00:00 2001 From: 0SlowPoke0 <142654792+0SlowPoke0@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:29:59 +0530 Subject: [PATCH] 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 --- .../document/document_message_handler.rs | 3 +- .../messages/tool/tool_messages/path_tool.rs | 35 ++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 9131341c..3258ecaf 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -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) } diff --git a/editor/src/messages/tool/tool_messages/path_tool.rs b/editor/src/messages/tool/tool_messages/path_tool.rs index 437ce9b7..a30cfeca 100644 --- a/editor/src/messages/tool/tool_messages/path_tool.rs +++ b/editor/src/messages/tool/tool_messages/path_tool.rs @@ -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); @@ -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) } ( @@ -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; @@ -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 } @@ -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);