From 5e1dd8a7cf27fe6453614aed98b20f12f02300e0 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Wed, 22 Aug 2018 18:41:47 -0400 Subject: [PATCH] Fix issue with importing projects from 2.0 where block comments were converted to workspace comments and the corresponding block was deleted. --- src/serialization/sb2.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/serialization/sb2.js b/src/serialization/sb2.js index b07d0f7a4..4c269448f 100644 --- a/src/serialization/sb2.js +++ b/src/serialization/sb2.js @@ -183,6 +183,23 @@ const parseScripts = function (scripts, blocks, addBroadcastMsg, getVariableId, blocks.createBlock(convertedBlocks[j]); } } + + // scriptIndexForComment is now greater than the index of the 'last' block in the flattened block array. + // If there are any comments referring to this index or any indices after it, they are comments that + // were originally created as block comments, detached from the block, and then had the associated block deleted. + // These comments should be imported as workspace comments + // by making their blockIDs (which currently refer to non-existing blocks) + // null (See #1452). + const blockCommentIndicesToFix = Object.keys(comments).filter(k => k >= scriptIndexForComment); + for (let i = 0; i < blockCommentIndicesToFix.length; i++) { + const currCommentIndex = blockCommentIndicesToFix[i]; + const currBlockComments = comments[currCommentIndex]; + currBlockComments.forEach(c => { + if (typeof c.blockId === 'number') { + c.blockId = null; + } + }); + } }; /**