@@ -107,7 +107,7 @@ my ($first_element) = first_value {$self->is_over_element($_, $x, $y)} reverse @
107107
108108$self -> select_elements(1, $first_element ) if defined $first_element ;
109109
110- $self -> run_actions_by_name(' Copy to clipboard' , [' Insert from clipboard' , 0, 0 ]) ;
110+ $self -> run_actions_by_name(' Copy to clipboard' , [' Insert from clipboard' , $self -> { COPY_OFFSET_X } // 1, $self -> { COPY_OFFSET_Y } // 1 ]) ;
111111}
112112
113113
@@ -134,22 +134,52 @@ $self->update_display();
134134
135135sub quick_link
136136{
137- my ($self ) = @_ ;
138- my ($x , $y ) = @{$self }{' MOUSE_X' , ' MOUSE_Y' } ;
137+ my ($self , $orthogonal ) = @_ ;
138+ my ($mx , $my ) = @{$self }{' MOUSE_X' , ' MOUSE_Y' } ;
139139
140140$self -> create_undo_snapshot() ;
141141
142- my ($destination_element ) = first_value {$self -> is_over_element($_ , $x , $y )} reverse @{$self -> {ELEMENTS }} ;
142+ my ($destination_element ) = first_value {$self -> is_over_element($_ , $mx , $my )} reverse @{$self -> {ELEMENTS }} ;
143143
144144if ($destination_element )
145145 {
146- connect_to_destination_element($self , $destination_element , $x , $y ) ;
146+ connect_to_destination_element($self , $destination_element , $mx , $my ) ;
147147 }
148148else
149149 {
150- my $new_box = $self -> add_new_element_named(' Asciio/box' , $x , $y ) ;
150+ my @selected_elements = $self -> get_selected_elements(1) ;
151+
152+ my ($ex , $ey ) = @selected_elements
153+ ? get_orthogonal_position(@{$selected_elements [0]}{qw/ X Y/ }, $mx , $my )
154+ : ($mx , $my ) ;
155+
156+ my $new_box = $self -> add_new_element_named(' Asciio/box' , $ex , $ey ) ;
151157
152- connect_to_destination_element($self , $new_box , $x , $y ) ;
158+ connect_to_destination_element($self , $new_box , $ex , $ey ) ;
159+ }
160+ }
161+
162+ sub get_orthogonal_position
163+ {
164+ my ($px , $py , $ax , $ay ) = @_ ;
165+
166+ my $o1_x = $px ;
167+ my $o1_y = $ay ;
168+ my $dx1 = $ax - $o1_x ;
169+ my $dist_sq1 = $dx1 * $dx1 ;
170+
171+ my $o2_x = $ax ;
172+ my $o2_y = $py ;
173+ my $dy2 = $ay - $o2_y ;
174+ my $dist_sq2 = $dy2 * $dy2 ;
175+
176+ if ($dist_sq1 <= $dist_sq2 )
177+ {
178+ return ($o1_x , $o1_y , ' Vertical' ) ;
179+ }
180+ else
181+ {
182+ return ($o2_x , $o2_y , ' Horizontal' ) ;
153183 }
154184}
155185
0 commit comments