File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,6 +109,9 @@ export class VariableMap
109109 variable : IVariableModel < IVariableState > ,
110110 newType : string ,
111111 ) : IVariableModel < IVariableState > {
112+ const oldType = variable . getType ( ) ;
113+ if ( oldType === newType ) return variable ;
114+
112115 this . variableMap . get ( variable . getType ( ) ) ?. delete ( variable . getId ( ) ) ;
113116 variable . setType ( newType ) ;
114117 const newTypeVariables =
@@ -118,6 +121,13 @@ export class VariableMap
118121 if ( ! this . variableMap . has ( newType ) ) {
119122 this . variableMap . set ( newType , newTypeVariables ) ;
120123 }
124+ eventUtils . fire (
125+ new ( eventUtils . get ( EventType . VAR_TYPE_CHANGE ) ) (
126+ variable ,
127+ oldType ,
128+ newType ,
129+ ) ,
130+ ) ;
121131 return variable ;
122132 }
123133
Original file line number Diff line number Diff line change @@ -505,5 +505,26 @@ suite('Variable Map', function () {
505505 } ) ;
506506 } ) ;
507507 } ) ;
508+
509+ suite ( 'variable type change events' , function ( ) {
510+ test ( 'are fired when a variable has its type changed' , function ( ) {
511+ const variable = this . variableMap . createVariable (
512+ 'name1' ,
513+ 'type1' ,
514+ 'id1' ,
515+ ) ;
516+ this . variableMap . changeVariableType ( variable , 'type2' ) ;
517+ assertEventFired (
518+ this . eventSpy ,
519+ Blockly . Events . VarTypeChange ,
520+ {
521+ oldType : 'type1' ,
522+ newType : 'type2' ,
523+ varId : 'id1' ,
524+ } ,
525+ this . workspace . id ,
526+ ) ;
527+ } ) ;
528+ } ) ;
508529 } ) ;
509530} ) ;
You can’t perform that action at this time.
0 commit comments