Skip to content

Commit 9804fca

Browse files
committed
Fixed ModuleContent.changeIds.
1 parent f294ad1 commit 9804fca

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

src/storage/module_content.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -263,30 +263,19 @@ export class ModuleContent {
263263
oldIdToNewId[oldMethodId] = method.methodId;
264264
});
265265

266-
// Change the ids in the blocks.
267-
const workspace = new Blockly.Workspace();
268-
const onChange = (event: Blockly.Events.Abstract) => {
269-
if (event.type === Blockly.Events.BLOCK_CREATE) {
270-
const blockCreateEvent = event as Blockly.Events.BlockCreate;
271-
if (blockCreateEvent.ids) {
272-
blockCreateEvent.ids.forEach(id => {
273-
const block = workspace.getBlockById(id);
274-
if (block) {
275-
if ('mrcChangeIds' in block && typeof block.mrcChangeIds === "function") {
276-
block.mrcChangeIds(oldIdToNewId);
277-
}
278-
}
279-
});
266+
if (Object.keys(oldIdToNewId).length) {
267+
// Change the ids in the blocks.
268+
const workspace = new Blockly.Workspace();
269+
Blockly.serialization.workspaces.load(this.blocks, workspace);
270+
workspace.getAllBlocks().forEach(block => {
271+
if ('mrcChangeIds' in block && typeof block.mrcChangeIds === "function") {
272+
block.mrcChangeIds(oldIdToNewId);
280273
}
281-
}
282-
};
283-
workspace.addChangeListener(onChange);
284-
Blockly.serialization.workspaces.load(this.blocks, workspace);
285-
workspace.removeChangeListener(onChange);
286-
this.blocks = Blockly.serialization.workspaces.save(workspace);
287-
288-
// Clean up the workspace
289-
workspace.dispose();
274+
});
275+
this.blocks = Blockly.serialization.workspaces.save(workspace);
290276

277+
// Clean up the workspace
278+
workspace.dispose();
279+
}
291280
}
292281
}

0 commit comments

Comments
 (0)