@@ -674,8 +674,10 @@ export class Navigation {
674674 ) : Blockly . RenderedConnection | null {
675675 const stationaryType = stationaryNode . getType ( ) ;
676676 const stationaryLoc = stationaryNode . getLocation ( ) ;
677+ const movingHasOutput = ! ! movingBlock . outputConnection ;
677678
678679 if ( stationaryNode . getType ( ) === Blockly . ASTNode . types . FIELD ) {
680+ // Can't connect a block to a field, so try going up to the source block.
679681 const sourceBlock = stationaryNode . getSourceBlock ( ) ;
680682 if ( ! sourceBlock ) return null ;
681683 return this . findInsertStartPoint (
@@ -689,7 +691,7 @@ export class Navigation {
689691 // Move to the block if we're trying to insert a statement block into
690692 // a value connection.
691693 if (
692- ! movingBlock . outputConnection &&
694+ ! movingHasOutput &&
693695 stationaryAsConnection . type === Blockly . ConnectionType . INPUT_VALUE
694696 ) {
695697 const sourceBlock = stationaryNode . getSourceBlock ( ) ;
@@ -709,7 +711,7 @@ export class Navigation {
709711 const stationaryBlock = stationaryLoc as Blockly . BlockSvg ;
710712
711713 // 1. Connect blocks to first compatible input
712- const inputType = movingBlock . outputConnection
714+ const inputType = movingHasOutput
713715 ? Blockly . inputs . inputTypes . VALUE
714716 : Blockly . inputs . inputTypes . STATEMENT ;
715717 const compatibleInputs = stationaryBlock . inputList . filter (
@@ -728,17 +730,24 @@ export class Navigation {
728730 }
729731
730732 // 2. Connect statement blocks to next connection.
731- if ( stationaryBlock . nextConnection && ! movingBlock . outputConnection ) {
733+ if ( stationaryBlock . nextConnection && ! movingHasOutput ) {
732734 return stationaryBlock . nextConnection ;
733735 }
734736
735737 // 3. Output connection. This will wrap around or displace.
736738 if ( stationaryBlock . outputConnection ) {
737- // Move to parent if we're trying to insert a statement block.
738- if (
739- ! movingBlock . outputConnection &&
739+ // Try to wrap.
740+ const target = stationaryBlock . outputConnection . targetConnection ;
741+ if ( movingHasOutput && target ) {
742+ const sourceNode = Blockly . ASTNode . createConnectionNode ( target ) ;
743+ if ( sourceNode ) {
744+ return this . findInsertStartPoint ( sourceNode , movingBlock ) ;
745+ }
746+ } else if (
747+ ! movingHasOutput &&
740748 stationaryNode . getType ( ) === Blockly . ASTNode . types . BLOCK
741749 ) {
750+ // Move to parent if we're trying to insert a statement block.
742751 const parent = stationaryNode . getSourceBlock ( ) ?. getParent ( ) ;
743752 if ( ! parent ) return null ;
744753 return this . findInsertStartPoint (
0 commit comments