@@ -66,7 +66,7 @@ export interface EventHandlerExtraState {
6666 senderType : SenderType ;
6767 /** The parameters of the event handler. */
6868 params : Parameter [ ] ;
69- /** The id of the mrc_event block that defines the event. */
69+ /** The mrcEventId of the mrc_event block that defines the event. */
7070 otherBlockId : string ,
7171 /**
7272 * The id of the mrc_mechanism block that adds the mechanism to the robot.
@@ -185,7 +185,7 @@ const EVENT_HANDLER = {
185185 let foundRobotEvent = false ;
186186 const robotEvents = editor . getEventsFromRobot ( ) ;
187187 for ( const robotEvent of robotEvents ) {
188- if ( robotEvent . blockId === this . mrcOtherBlockId ) {
188+ if ( robotEvent . eventId === this . mrcOtherBlockId ) {
189189 foundRobotEvent = true ;
190190 if ( this . getFieldValue ( FIELD_EVENT_NAME ) !== robotEvent . name ) {
191191 this . setFieldValue ( robotEvent . name , FIELD_EVENT_NAME ) ;
@@ -289,6 +289,17 @@ const EVENT_HANDLER = {
289289 this . setFieldValue ( newName , FIELD_SENDER ) ;
290290 }
291291 } ,
292+ /**
293+ * mrcChangeIds is called when a module is copied so that the copy has different ids than the original.
294+ */
295+ mrcChangeIds : function ( this : EventHandlerBlock , oldIdToNewId : { [ oldId : string ] : string } ) : void {
296+ if ( this . mrcOtherBlockId in oldIdToNewId ) {
297+ this . mrcOtherBlockId = oldIdToNewId [ this . mrcOtherBlockId ] ;
298+ }
299+ if ( this . mrcMechanismBlockId && this . mrcMechanismBlockId in oldIdToNewId ) {
300+ this . mrcMechanismBlockId = oldIdToNewId [ this . mrcMechanismBlockId ] ;
301+ }
302+ } ,
292303} ;
293304
294305export function setup ( ) : void {
@@ -406,7 +417,7 @@ function createRobotEventHandlerBlock(
406417 const extraState : EventHandlerExtraState = {
407418 senderType : SenderType . ROBOT ,
408419 params : [ ] ,
409- otherBlockId : event . blockId ,
420+ otherBlockId : event . eventId ,
410421 } ;
411422 event . args . forEach ( arg => {
412423 extraState . params . push ( {
0 commit comments