Skip to content

Commit dce9a08

Browse files
gonfunkocwillisf
authored andcommitted
fix: use derived IDs for block comments (#11)
1 parent 4b31377 commit dce9a08

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/scratch-vm/src/engine/adapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const domToBlock = function (blockDOM, blocks, isTopBlock, parent) {
8888
}
8989
case 'comment':
9090
{
91-
block.comment = xmlChild.attribs.id;
91+
block.comment = `${block.id}_comment`;
9292
break;
9393
}
9494
case 'value':

packages/scratch-vm/src/serialization/sb3.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,14 @@ const deserializeBlocks = function (blocks) {
842842
block.id = blockId; // add id back to block since it wasn't serialized
843843
block.inputs = deserializeInputs(block.inputs, blockId, blocks);
844844
block.fields = deserializeFields(block.fields);
845+
846+
if (block.comment) {
847+
// Pre-Blockly v12 Scratch used arbitrary IDs for block comments.
848+
// Newer versions use an ID based on the parent block's ID instead,
849+
// so disregard the actual saved value and replace it with the
850+
// synthesized one.
851+
block.comment = `${block.id}_comment`;
852+
}
845853
}
846854
return blocks;
847855
};
@@ -1047,7 +1055,7 @@ const parseScratchObject = function (object, runtime, extensions, zip, assets) {
10471055
for (const commentId in object.comments) {
10481056
const comment = object.comments[commentId];
10491057
const newComment = new Comment(
1050-
commentId,
1058+
comment.blockId ? `${comment.blockId}_comment` : commentId,
10511059
comment.text,
10521060
comment.x,
10531061
comment.y,

0 commit comments

Comments
 (0)