@@ -1096,10 +1096,11 @@ class Blocks {
10961096 that . blockList [ blk ] . container . updateCache ( ) ;
10971097
10981098 if ( that . blockList [ blk ] . value !== that . blockList [ oldBlock ] . value ) {
1099+ const metadata = that . actionMetadata ( parentblk ) ;
10991100 that . newNameddoBlock (
11001101 that . blockList [ blk ] . value ,
1101- that . actionHasReturn ( parentblk ) ,
1102- that . actionHasArgs ( parentblk )
1102+ metadata . hasReturn ,
1103+ metadata . hasArgs
11031104 ) ;
11041105 const blockPalette = that . activity . palettes . dict [ "action" ] ;
11051106 for ( let b = 0 ; b < blockPalette . protoList . length ; b ++ ) {
@@ -2005,10 +2006,11 @@ class Blocks {
20052006 this . activity . palettes . dict [ "action" ] . hideMenu ( true ) ;
20062007 }
20072008
2009+ const metadata = this . actionMetadata ( newBlock ) ;
20082010 this . newNameddoBlock (
20092011 myBlock . value ,
2010- this . actionHasReturn ( newBlock ) ,
2011- this . actionHasArgs ( newBlock )
2012+ metadata . hasReturn ,
2013+ metadata . hasArgs
20122014 ) ;
20132015 const blockPalette = this . activity . palettes . dict [ "action" ] ;
20142016 for ( let b = 0 ; b < blockPalette . protoList . length ; b ++ ) {
@@ -2107,10 +2109,11 @@ class Blocks {
21072109 }
21082110 this . blockList [ thisBlock ] . text . text = label ;
21092111 this . blockList [ thisBlock ] . container . updateCache ( ) ;
2112+ const metadata = this . actionMetadata ( b ) ;
21102113 this . newNameddoBlock (
21112114 this . blockList [ thisBlock ] . value ,
2112- this . actionHasReturn ( b ) ,
2113- this . actionHasArgs ( b )
2115+ metadata . hasReturn ,
2116+ metadata . hasArgs
21142117 ) ;
21152118 this . setActionProtoVisibility ( false ) ;
21162119 }
@@ -3444,8 +3447,8 @@ class Blocks {
34443447 /** Make sure we don't make two actions with the same name. */
34453448 value = this . findUniqueActionName ( _ ( "action" ) ) ;
34463449 if ( value !== _ ( "action" ) ) {
3447- /** TODO: are there return or arg blocks? */
3448- this . newNameddoBlock ( value , false , false ) ;
3450+ const metadata = this . actionMetadata ( blk ) ;
3451+ this . newNameddoBlock ( value , metadata . hasReturn , metadata . hasArgs ) ;
34493452 /** this.activity.palettes.hide(); */
34503453 this . activity . palettes . updatePalettes ( "action" ) ;
34513454 /** this.activity.palettes.show(); */
@@ -6665,11 +6668,12 @@ class Blocks {
66656668 const myBlock = this . blockList [ blk ] ;
66666669 const c = myBlock . connections [ 1 ] ;
66676670 if ( c != null && this . blockList [ c ] . value !== _ ( "action" ) ) {
6671+ const metadata = this . actionMetadata ( blk ) ;
66686672 if (
66696673 this . newNameddoBlock (
66706674 this . blockList [ c ] . value ,
6671- this . actionHasReturn ( blk ) ,
6672- this . actionHasArgs ( blk )
6675+ metadata . hasReturn ,
6676+ metadata . hasArgs
66736677 )
66746678 ) {
66756679 updatePalettes = true ;
@@ -6759,45 +6763,47 @@ class Blocks {
67596763 } ;
67606764
67616765 /**
6762- * Look for a Return block in an action stack.
6766+ * Look for Return and Arg blocks in an action stack.
67636767 * @param - blk - block
67646768 * @public
6765- * @returns boolean
6769+ * @returns { hasReturn: boolean, hasArgs: boolean }
67666770 */
6767- this . actionHasReturn = blk => {
6771+ this . actionMetadata = blk => {
67686772 if ( this . blockList [ blk ] . name !== "action" ) {
6769- return false ;
6773+ return { hasReturn : false , hasArgs : false } ;
67706774 }
67716775 this . findDragGroup ( blk ) ;
6776+ let hasReturn = false ;
6777+ let hasArgs = false ;
67726778 for ( let b = 0 ; b < this . dragGroup . length ; b ++ ) {
6773- if ( this . blockList [ this . dragGroup [ b ] ] . name === "return" ) {
6774- return true ;
6779+ const name = this . blockList [ this . dragGroup [ b ] ] . name ;
6780+ if ( name === "return" ) {
6781+ hasReturn = true ;
6782+ } else if ( name === "arg" || name === "namedarg" ) {
6783+ hasArgs = true ;
6784+ }
6785+ if ( hasReturn && hasArgs ) {
6786+ break ;
67756787 }
67766788 }
6777- return false ;
6789+ return { hasReturn , hasArgs } ;
67786790 } ;
67796791
6792+ /**
6793+ * Look for a Return block in an action stack.
6794+ * @param - blk - block
6795+ * @public
6796+ * @returns boolean
6797+ */
6798+ this . actionHasReturn = blk => this . actionMetadata ( blk ) . hasReturn ;
6799+
67806800 /**
67816801 * Look for an Arg block in an action stack.
67826802 * @param - blk - block
67836803 * @public
67846804 * @returns boolean
67856805 */
6786- this . actionHasArgs = blk => {
6787- if ( this . blockList [ blk ] . name !== "action" ) {
6788- return false ;
6789- }
6790- this . findDragGroup ( blk ) ;
6791- for ( let b = 0 ; b < this . dragGroup . length ; b ++ ) {
6792- if (
6793- this . blockList [ this . dragGroup [ b ] ] . name === "arg" ||
6794- this . blockList [ this . dragGroup [ b ] ] . name === "namedarg"
6795- ) {
6796- return true ;
6797- }
6798- }
6799- return false ;
6800- } ;
6806+ this . actionHasArgs = blk => this . actionMetadata ( blk ) . hasArgs ;
68016807
68026808 /**
68036809 * Move the stack associated with blk to the top.
0 commit comments