@@ -46,6 +46,7 @@ type Parameter = {
4646
4747export type ClassMethodDefBlock = Blockly . Block & ClassMethodDefMixin & Blockly . BlockSvg ;
4848interface ClassMethodDefMixin extends ClassMethodDefMixinType {
49+ mrcMethodId : string ,
4950 mrcCanChangeSignature : boolean ,
5051 mrcCanBeCalledWithinClass : boolean ,
5152 mrcCanBeCalledOutsideClass : boolean ,
@@ -58,6 +59,10 @@ type ClassMethodDefMixinType = typeof CLASS_METHOD_DEF;
5859
5960/** Extra state for serialising call_python_* blocks. */
6061type ClassMethodDefExtraState = {
62+ /**
63+ * The id that identifies this method definition.
64+ */
65+ methodId ?: string ,
6166 /**
6267 * Can change name and parameters and return type
6368 */
@@ -109,6 +114,7 @@ const CLASS_METHOD_DEF = {
109114 saveExtraState : function (
110115 this : ClassMethodDefBlock ) : ClassMethodDefExtraState {
111116 const extraState : ClassMethodDefExtraState = {
117+ methodId : this . mrcMethodId ,
112118 canChangeSignature : this . mrcCanChangeSignature ,
113119 canBeCalledWithinClass : this . mrcCanBeCalledWithinClass ,
114120 canBeCalledOutsideClass : this . mrcCanBeCalledOutsideClass ,
@@ -134,6 +140,7 @@ const CLASS_METHOD_DEF = {
134140 this : ClassMethodDefBlock ,
135141 extraState : ClassMethodDefExtraState
136142 ) : void {
143+ this . mrcMethodId = extraState . methodId ? extraState . methodId : this . id ;
137144 this . mrcCanChangeSignature = extraState . canChangeSignature ;
138145 this . mrcCanBeCalledWithinClass = extraState . canBeCalledWithinClass ;
139146 this . mrcCanBeCalledOutsideClass = extraState . canBeCalledOutsideClass ;
@@ -196,7 +203,7 @@ const CLASS_METHOD_DEF = {
196203 if ( this . mrcCanBeCalledWithinClass ) {
197204 const methodForWithin = this . getMethodForWithin ( ) ;
198205 if ( methodForWithin ) {
199- mutateMethodCallers ( this . workspace , this . id , methodForWithin ) ;
206+ mutateMethodCallers ( this . workspace , this . mrcMethodId , methodForWithin ) ;
200207 }
201208 }
202209 } ,
@@ -263,13 +270,13 @@ const CLASS_METHOD_DEF = {
263270 const oldName = nameField . getValue ( ) ;
264271 if ( oldName && oldName !== name && oldName !== legalName ) {
265272 // Rename any callers.
266- renameMethodCallers ( this . workspace , this . id , legalName ) ;
273+ renameMethodCallers ( this . workspace , this . mrcMethodId , legalName ) ;
267274 }
268275 return legalName ;
269276 } ,
270277 getMethod : function ( this : ClassMethodDefBlock ) : storageModuleContent . Method | null {
271278 const method : storageModuleContent . Method = {
272- blockId : this . id ,
279+ methodId : this . mrcMethodId ,
273280 visibleName : this . getFieldValue ( FIELD_METHOD_NAME ) ,
274281 pythonName : this . mrcFuncName ? this . mrcFuncName : '' ,
275282 returnType : this . mrcReturnType ,
@@ -307,6 +314,14 @@ const CLASS_METHOD_DEF = {
307314 getMethodName : function ( this : ClassMethodDefBlock ) : string {
308315 return this . getFieldValue ( FIELD_METHOD_NAME ) ;
309316 } ,
317+ /**
318+ * mrcChangeIds is called when a module is copied so that the copy has different ids than the original.
319+ */
320+ mrcChangeIds : function ( this : ClassMethodDefBlock , oldIdToNewId : { [ oldId : string ] : string } ) : void {
321+ if ( this . mrcMethodId in oldIdToNewId ) {
322+ this . mrcMethodId = oldIdToNewId [ this . mrcMethodId ] ;
323+ }
324+ } ,
310325} ;
311326
312327/**
0 commit comments