@@ -137,7 +137,8 @@ class Blocks extends React.Component {
137137 'onWorkspaceMetricsChange' ,
138138 'setBlocks' ,
139139 'setLocale' ,
140- 'handleEnableProcedureReturns'
140+ 'handleEnableProcedureReturns' ,
141+ 'handleFieldBoxChange'
141142 ] ) ;
142143 this . ScratchBlocks . prompt = this . handlePromptStart ;
143144 this . ScratchBlocks . customPrompt = this . handleCustomPrompt ;
@@ -355,6 +356,7 @@ class Blocks extends React.Component {
355356
356357 attachVM ( ) {
357358 this . workspace . addChangeListener ( this . props . vm . blockListener ) ;
359+ this . workspace . addChangeListener ( this . handleFieldBoxChange ) ;
358360 this . flyoutWorkspace = this . workspace
359361 . getFlyout ( )
360362 . getWorkspace ( ) ;
@@ -495,6 +497,7 @@ class Blocks extends React.Component {
495497
496498 // Remove and reattach the workspace listener (but allow flyout events)
497499 this . workspace . removeChangeListener ( this . props . vm . blockListener ) ;
500+ this . workspace . removeChangeListener ( this . handleFieldBoxChange ) ;
498501 const dom = this . ScratchBlocks . Xml . textToDom ( data . xml ) ;
499502 try {
500503 this . ScratchBlocks . Xml . clearWorkspaceAndLoadFromXml ( dom , this . workspace ) ;
@@ -514,6 +517,7 @@ class Blocks extends React.Component {
514517 log . error ( error ) ;
515518 }
516519 this . workspace . addChangeListener ( this . props . vm . blockListener ) ;
520+ this . workspace . addChangeListener ( this . handleFieldBoxChange ) ;
517521
518522 if ( this . props . vm . editingTarget && this . props . workspaceMetrics . targets [ this . props . vm . editingTarget . id ] ) {
519523 const { scrollX, scrollY, scale} = this . props . workspaceMetrics . targets [ this . props . vm . editingTarget . id ] ;
@@ -734,6 +738,34 @@ class Blocks extends React.Component {
734738 this . workspace . enableProcedureReturns ( ) ;
735739 this . requestToolboxUpdate ( ) ;
736740 }
741+ handleFieldBoxChange ( args ) {
742+ // update checkbox states with menu-dependent blocks
743+ const editingTarget = this . props . vm . editingTarget ;
744+ if ( ! editingTarget || args . element !== 'field' ) return ;
745+
746+ const flyout = this . flyoutWorkspace ;
747+ if ( ! flyout ) return ;
748+
749+ let block = editingTarget . blocks . _blocks [ args . id ] ;
750+ if ( typeof block === 'undefined' ) return ;
751+
752+ // check if monitoring
753+ const monitorState = this . props . vm . runtime . getMonitorState ( ) ;
754+ const shouldCheck = (
755+ monitorState . get ( `${ args . id } _${ args . value } ` ) !== undefined ||
756+ monitorState . get ( `${ args . id } _${ args . value . toLowerCase ( ) } ` ) !== undefined
757+ ) ;
758+
759+ const checkbox = flyout . checkboxes_ [ args . id ] ;
760+ if ( checkbox ) {
761+ checkbox . clicked = shouldCheck ;
762+ if ( shouldCheck ) {
763+ this . ScratchBlocks . utils . addClass ( checkbox . svgRoot , 'checked' ) ;
764+ } else {
765+ this . ScratchBlocks . utils . removeClass ( checkbox . svgRoot , 'checked' ) ;
766+ }
767+ }
768+ }
737769 render ( ) {
738770 /* eslint-disable no-unused-vars */
739771 const {
0 commit comments