@@ -131,20 +131,21 @@ class CustomExtensionModal extends React.Component {
131131 if ( this . props . swapId ) {
132132 const runtime = this . props . vm . runtime ;
133133 this . props . vm . extensionManager . prepareSwap ( this . props . swapId ) ;
134- let extIdx = runtime . _blockInfo . findIndex ( ext => ext . id === this . props . swapId ) ;
135134 const loadedIds = await this . props . vm . extensionManager . loadExtensionURL ( url ) ;
136135 if ( ! loadedIds . includes ( this . props . swapId ) ) {
137136 for ( const ext of loadedIds ) this . props . vm . extensionManager . removeExtension ( ext ) ;
138137 // eslint-disable-next-line no-alert
139138 alert ( 'The extension you used for the edit had a different ID than the one you were editing.' ) ;
140139 }
141140 loadedIds . forEach ( extId => {
142- const idx = runtime . _blockInfo . findLastIndex ( ext => ext . id === extId ) ;
143- const ext = runtime . _blockInfo [ idx ] ;
144- runtime . _blockInfo . splice ( idx , 1 ) ;
145- runtime . _blockInfo . splice ( extIdx , 0 , ext ) ;
146- extIdx ++ ;
141+ const idx = runtime . _blockInfo . findIndex ( ext => ext . id === extId ) ;
142+ const doubleIdx = runtime . _blockInfo . findIndex ( ( ext , i ) => ext . id === extId && i !== idx ) ;
143+ if ( doubleIdx === - 1 ) return ;
144+ const extInfo = runtime . _blockInfo [ idx ] ;
145+ runtime . _blockInfo . splice ( doubleIdx , 1 ) ;
146+ runtime . _blockInfo . splice ( idx , 1 , extInfo ) ;
147147 } ) ;
148+ this . props . vm . refreshWorkspace ( ) ;
148149 } else {
149150 await this . props . vm . extensionManager . loadExtensionURL ( url ) ;
150151 }
0 commit comments