@@ -181,17 +181,17 @@ suite('Statement move tests', function () {
181181 * pressing right or down arrow n times.
182182 */
183183 const EXPECTED_SIMPLE = [
184- { id : 'p5_canvas' , index : 1 } , // Next; starting location.
185- { id : 'text_print' , index : 0 } , // Previous.
186- { id : 'text_print' , index : 1 } , // Next.
187- { id : 'controls_if' , index : 3 } , // Statement input for "if" .
188- { id : 'controls_repeat_ext' , index : 3 } , // Statement input.
189- { id : 'controls_repeat_ext' , index : 1 } , // Next.
190- { id : 'controls_if' , index : 5 } , // Statement input for "else if".
191- { id : 'controls_if' , index : 6 } , // Statement input for "else" .
192- { id : 'controls_if' , index : 1 } , // Next.
193- { id : 'p5_draw' , index : 0 } , // Statement input.
194- { id : 'p5_canvas' , index : 1 } , // Next; starting location again.
184+ { id : 'p5_canvas' , index : 1 , ownIndex : 0 } , // Next; starting location.
185+ { id : 'text_print' , index : 0 , ownIndex : 1 } , // Previous.
186+ { id : 'text_print' , index : 1 , ownIndex : 0 } , // Next.
187+ { id : 'controls_if' , index : 3 , ownIndex : 0 } , // "If" statement input .
188+ { id : 'controls_repeat_ext' , index : 3 , ownIndex : 0 } , // Statement input.
189+ { id : 'controls_repeat_ext' , index : 1 , ownIndex : 0 } , // Next.
190+ { id : 'controls_if' , index : 5 , ownIndex : 0 } , // "Else if" statement input .
191+ { id : 'controls_if' , index : 6 , ownIndex : 0 } , // "Else" statement input .
192+ { id : 'controls_if' , index : 1 , ownIndex : 0 } , // Next.
193+ { id : 'p5_draw' , index : 0 , ownIndex : 0 } , // Statement input.
194+ { id : 'p5_canvas' , index : 1 , ownIndex : 0 } , // Next; starting location again.
195195 ] ;
196196 const EXPECTED_SIMPLE_REVERSED = EXPECTED_SIMPLE . slice ( ) . reverse ( ) ;
197197
@@ -430,11 +430,11 @@ function getCoordinate(
430430 * @returns A promise setting to either null if there is no connection
431431 * candidate, or otherwise if there is one to
432432 *
433- * {id, index}
433+ * {id, index, ownIndex }
434434 *
435- * where id is the block ID of the neighbour, and index is the
436- * index of the connection to which the currently-moving block is
437- * connected., or to null if there is no connection candidate .
435+ * where id is the block ID of the neighbour, index is the index
436+ * of the candidate connection on the neighbour, and ownIndex is
437+ * the index of the candidate connection on the moving block .
438438 */
439439function getConnectionCandidate (
440440 browser : Browser ,
@@ -450,12 +450,14 @@ function getConnectionCandidate(
450450 block . getDragStrategy ( ) as Blockly . dragging . BlockDragStrategy ;
451451 if ( ! dragStrategy ) throw new Error ( 'no drag strategy' ) ;
452452 // @ts -expect-error connectionCandidate is private.
453- const neighbour = dragStrategy . connectionCandidate ?. neighbour ;
454- if ( ! neighbour ) return null ;
455- const candidateBlock = neighbour . getSourceBlock ( ) ;
456- if ( ! candidateBlock ) return null ;
457- const blockConnections = candidateBlock . getConnections_ ( true ) ;
458- const index = blockConnections . indexOf ( neighbour ) ;
459- return { id : candidateBlock . id , index} ;
453+ const candidate = dragStrategy . connectionCandidate ;
454+ if ( ! candidate ) return null ;
455+ const neighbourBlock = candidate . neighbour . getSourceBlock ( ) ;
456+ if ( ! neighbourBlock ) throw new TypeError ( 'connection has no source block' ) ;
457+ const neighbourConnections = neighbourBlock . getConnections_ ( true ) ;
458+ const index = neighbourConnections . indexOf ( candidate . neighbour ) ;
459+ const ownConnections = block . getConnections_ ( true ) ;
460+ const ownIndex = ownConnections . indexOf ( candidate . local ) ;
461+ return { id : neighbourBlock . id , index, ownIndex} ;
460462 } ) ;
461463}
0 commit comments