11use super :: tool_prelude:: * ;
2- use crate :: consts:: { COLOR_OVERLAY_BLUE , DEFAULT_STROKE_WIDTH , HIDE_HANDLE_DISTANCE , LINE_ROTATE_SNAP_ANGLE , SEGMENT_OVERLAY_SIZE } ;
2+ use crate :: consts:: { COLOR_OVERLAY_BLUE , DEFAULT_STROKE_WIDTH , DOUBLE_CLICK_MILLISECONDS , DRAG_THRESHOLD , HIDE_HANDLE_DISTANCE , LINE_ROTATE_SNAP_ANGLE , SEGMENT_OVERLAY_SIZE } ;
33use crate :: messages:: input_mapper:: utility_types:: input_mouse:: MouseKeys ;
44use crate :: messages:: portfolio:: document:: node_graph:: document_node_definitions:: resolve_document_node_type;
55use crate :: messages:: portfolio:: document:: overlays:: utility_functions:: path_overlays;
@@ -410,6 +410,9 @@ struct PenToolData {
410410 /// and Ctrl is pressed near the anchor to make it colinear with its opposite handle.
411411 angle_locked : bool ,
412412 path_closed : bool ,
413+ last_click_time : Option < u64 > ,
414+ last_click_pos : Option < DVec2 > ,
415+ pending_double_click_confirm : bool ,
413416
414417 handle_mode : HandleMode ,
415418 prior_segment_layer : Option < LayerNodeIdentifier > ,
@@ -446,6 +449,18 @@ impl PenToolData {
446449 self . latest_points . clear ( ) ;
447450 self . point_index = 0 ;
448451 self . snap_manager . cleanup ( responses) ;
452+ self . pending_double_click_confirm = false ;
453+ self . last_click_time = None ;
454+ self . last_click_pos = None ;
455+ }
456+
457+ fn update_click_timing ( & mut self , time : u64 , position : DVec2 ) -> bool {
458+ let within_time = self . last_click_time . map ( |last_time| time. saturating_sub ( last_time) <= DOUBLE_CLICK_MILLISECONDS ) . unwrap_or ( false ) ;
459+ let within_distance = self . last_click_pos . map ( |last_pos| last_pos. distance ( position) <= DRAG_THRESHOLD ) . unwrap_or ( false ) ;
460+ let is_double_click = within_time && within_distance;
461+ self . last_click_time = Some ( time) ;
462+ self . last_click_pos = Some ( position) ;
463+ is_double_click
449464 }
450465
451466 /// Check whether target handle is primary, end, or `self.handle_end`
@@ -1816,6 +1831,8 @@ impl Fsm for PenToolFsmState {
18161831 self
18171832 }
18181833 ( PenToolFsmState :: Ready , PenToolMessage :: DragStart { append_to_selected } ) => {
1834+ tool_data. pending_double_click_confirm = false ;
1835+ let _ = tool_data. update_click_timing ( input. time , input. mouse . position ) ;
18191836 responses. add ( DocumentMessage :: StartTransaction ) ;
18201837 tool_data. handle_mode = HandleMode :: Free ;
18211838
@@ -1838,6 +1855,14 @@ impl Fsm for PenToolFsmState {
18381855 state
18391856 }
18401857 ( PenToolFsmState :: PlacingAnchor , PenToolMessage :: DragStart { append_to_selected } ) => {
1858+ let double_click = if tool_data. buffering_merged_vector {
1859+ false
1860+ } else {
1861+ tool_data. update_click_timing ( input. time , input. mouse . position )
1862+ } ;
1863+ if !tool_data. buffering_merged_vector {
1864+ tool_data. pending_double_click_confirm = double_click;
1865+ }
18411866 let point = SnapCandidatePoint :: handle ( document. metadata ( ) . document_to_viewport . inverse ( ) . transform_point2 ( input. mouse . position ) ) ;
18421867 let snapped = tool_data. snap_manager . free_snap ( & SnapData :: new ( document, input) , & point, SnapTypeConfiguration :: default ( ) ) ;
18431868 let viewport = document. metadata ( ) . document_to_viewport . transform_point2 ( snapped. snapped_point_document ) ;
@@ -1892,9 +1917,16 @@ impl Fsm for PenToolFsmState {
18921917 }
18931918 ( PenToolFsmState :: DraggingHandle ( _) , PenToolMessage :: DragStop ) => {
18941919 tool_data. cleanup_target_selections ( shape_editor, layer, document, responses) ;
1895- tool_data
1920+ let next_state = tool_data
18961921 . finish_placing_handle ( SnapData :: new ( document, input) , transform, preferences, responses)
1897- . unwrap_or ( PenToolFsmState :: PlacingAnchor )
1922+ . unwrap_or ( PenToolFsmState :: PlacingAnchor ) ;
1923+ if tool_data. pending_double_click_confirm && matches ! ( next_state, PenToolFsmState :: PlacingAnchor ) {
1924+ tool_data. pending_double_click_confirm = false ;
1925+ responses. add ( PenToolMessage :: Confirm ) ;
1926+ } else {
1927+ tool_data. pending_double_click_confirm = false ;
1928+ }
1929+ next_state
18981930 }
18991931 (
19001932 PenToolFsmState :: DraggingHandle ( _) ,
0 commit comments