@@ -675,11 +675,33 @@ export class Navigation {
675675 const stationaryType = stationaryNode . getType ( ) ;
676676 const stationaryLoc = stationaryNode . getLocation ( ) ;
677677
678- if ( stationaryNode . isConnection ( ) ) {
679- // Connect the moving block to the stationary connection using
680- // the most plausible connection on the moving block.
678+ if ( stationaryNode . getType ( ) === Blockly . ASTNode . types . FIELD ) {
679+ const sourceBlock = stationaryNode . getSourceBlock ( ) ;
680+ if ( ! sourceBlock ) return false ;
681+ return this . tryToConnectBlock (
682+ Blockly . ASTNode . createBlockNode ( sourceBlock ) ,
683+ movingBlock ,
684+ ) ;
685+ } else if ( stationaryNode . isConnection ( ) ) {
681686 const stationaryAsConnection =
682687 stationaryLoc as Blockly . RenderedConnection ;
688+
689+ // Move to the block if we're trying to insert a statement block into
690+ // a value connection.
691+ if (
692+ ! movingBlock . outputConnection &&
693+ stationaryAsConnection . type === Blockly . ConnectionType . INPUT_VALUE
694+ ) {
695+ const sourceBlock = stationaryNode . getSourceBlock ( ) ;
696+ if ( ! sourceBlock ) return false ;
697+ return this . tryToConnectBlock (
698+ Blockly . ASTNode . createBlockNode ( sourceBlock ) ,
699+ movingBlock ,
700+ ) ;
701+ }
702+
703+ // Connect the moving block to the stationary connection using
704+ // the most plausible connection on the moving block.
683705 return this . insertBlock ( movingBlock , stationaryAsConnection ) ;
684706 } else if ( stationaryType === Blockly . ASTNode . types . WORKSPACE ) {
685707 return this . moveBlockToWorkspace ( movingBlock , stationaryNode ) ;
@@ -715,6 +737,18 @@ export class Navigation {
715737
716738 // 3. Output connection. This will wrap around or displace.
717739 if ( stationaryBlock . outputConnection ) {
740+ // Move to parent if we're trying to insert a statement block.
741+ if (
742+ ! movingBlock . outputConnection &&
743+ stationaryNode . getType ( ) === Blockly . ASTNode . types . BLOCK
744+ ) {
745+ const parent = stationaryNode . getSourceBlock ( ) ?. getParent ( ) ;
746+ if ( ! parent ) return false ;
747+ return this . tryToConnectBlock (
748+ Blockly . ASTNode . createBlockNode ( parent ) ,
749+ movingBlock ,
750+ ) ;
751+ }
718752 return this . insertBlock ( movingBlock , stationaryBlock . outputConnection ) ;
719753 }
720754 }
0 commit comments