File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed
Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,12 @@ export abstract class Flyout
135135 */
136136 private reflowWrapper : ( ( e : AbstractEvent ) => void ) | null = null ;
137137
138+ /**
139+ * If true, prevents the reflow wrapper from running. Used to prevent infinite
140+ * recursion.
141+ */
142+ private inhibitReflowWrapper = false ;
143+
138144 /**
139145 * List of flyout elements.
140146 */
@@ -649,6 +655,7 @@ export abstract class Flyout
649655 // accommodates e.g. resizing a non-autoclosing flyout in response to the
650656 // user typing long strings into fields on the blocks in the flyout.
651657 this . reflowWrapper = ( event ) => {
658+ if ( this . inhibitReflowWrapper ) return ;
652659 if (
653660 event . type === EventType . BLOCK_CHANGE ||
654661 event . type === EventType . BLOCK_FIELD_INTERMEDIATE_CHANGE
@@ -846,13 +853,9 @@ export abstract class Flyout
846853 * Reflow flyout contents.
847854 */
848855 reflow ( ) {
849- if ( this . reflowWrapper ) {
850- this . workspace_ . removeChangeListener ( this . reflowWrapper ) ;
851- }
856+ this . inhibitReflowWrapper = true ;
852857 this . reflowInternal_ ( ) ;
853- if ( this . reflowWrapper ) {
854- this . workspace_ . addChangeListener ( this . reflowWrapper ) ;
855- }
858+ this . inhibitReflowWrapper = false ;
856859 }
857860
858861 /**
Original file line number Diff line number Diff line change @@ -43,6 +43,26 @@ suite('Flyout', function () {
4343 sharedTestTeardown . call ( this ) ;
4444 } ) ;
4545
46+ suite ( 'workspace change listeners' , function ( ) {
47+ test ( 'are triggered when a child block changes' , function ( ) {
48+ let listenerTriggered = false ;
49+ const listener = ( e ) => {
50+ if ( e . type === Blockly . Events . BLOCK_CHANGE ) {
51+ listenerTriggered = true ;
52+ }
53+ } ;
54+ this . workspace . getFlyout ( ) . getWorkspace ( ) . addChangeListener ( listener ) ;
55+ const boolBlock = this . workspace
56+ . getFlyout ( )
57+ . getWorkspace ( )
58+ . getBlocksByType ( 'logic_compare' ) [ 0 ] ;
59+ boolBlock . getField ( 'OP' ) . setValue ( 'LTE' ) ;
60+ this . clock . tick ( 1000 ) ;
61+ assert . isTrue ( listenerTriggered ) ;
62+ this . workspace . getFlyout ( ) . getWorkspace ( ) . removeChangeListener ( listener ) ;
63+ } ) ;
64+ } ) ;
65+
4666 suite ( 'position' , function ( ) {
4767 suite ( 'vertical flyout' , function ( ) {
4868 suite ( 'simple flyout' , function ( ) {
You can’t perform that action at this time.
0 commit comments