@@ -175,16 +175,32 @@ const MECHANISM = {
175175 if ( editor ) {
176176 // Find the mechanism.
177177 let foundMechanism : storageModule . Mechanism | null = null ;
178- const components : storageModuleContent . Component [ ] = [ ]
179- for ( const mechanism of editor . getMechanisms ( ) ) {
180- if ( mechanism . moduleId === this . mrcMechanismModuleId ) {
181- foundMechanism = mechanism ;
182- components . push ( ...editor . getComponentsFromMechanism ( mechanism ) ) ;
183- break ;
178+
179+ if ( this . mrcMechanismModuleId ) {
180+ // Find the mechanism by module id.
181+ for ( const mechanism of editor . getMechanisms ( ) ) {
182+ if ( mechanism . moduleId === this . mrcMechanismModuleId ) {
183+ foundMechanism = mechanism ;
184+ break ;
185+ }
186+ }
187+ } else {
188+ // Find the mechanism by class name.
189+ const className = this . getFieldValue ( FIELD_TYPE ) ;
190+ for ( const mechanism of editor . getMechanisms ( ) ) {
191+ if ( mechanism . className === className ) {
192+ // Grap the mechanism module id, so we have it for next time.
193+ this . mrcMechanismModuleId = mechanism . moduleId ;
194+ foundMechanism = mechanism ;
195+ break ;
196+ }
184197 }
185198 }
186199
187200 if ( foundMechanism ) {
201+ const components : storageModuleContent . Component [ ] = [ ] ;
202+ components . push ( ...editor . getComponentsFromMechanism ( foundMechanism ) ) ;
203+
188204 // If the mechanism class name has changed, update this blcok.
189205 if ( this . getFieldValue ( FIELD_TYPE ) !== foundMechanism . className ) {
190206 this . setFieldValue ( foundMechanism . className , FIELD_TYPE ) ;
0 commit comments