From f079eb4bbd6aa2024bb5755edf70ec6b666fa18c Mon Sep 17 00:00:00 2001
From: Karishma Chadha <kchadha@scratch.mit.edu>
Date: Mon, 28 May 2018 21:24:47 -0400
Subject: [PATCH] Don't serialize x and y for sb2 comments so that they can be
 auto positioned.

---
 src/engine/comment.js    | 4 ++--
 src/serialization/sb2.js | 9 ++++++---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/engine/comment.js b/src/engine/comment.js
index acd796681..2049e5729 100644
--- a/src/engine/comment.js
+++ b/src/engine/comment.js
@@ -17,8 +17,8 @@ class Comment {
     constructor (id, text, x, y, width, height, minimized) {
         this.id = id || uid();
         this.text = text;
-        this.x = cast.toNumber(x);
-        this.y = cast.toNumber(y);
+        this.x = x;
+        this.y = y;
         this.width = Math.max(cast.toNumber(width), Comment.MIN_WIDTH);
         this.height = Math.max(cast.toNumber(height), Comment.MIN_HEIGHT);
         this.minimized = minimized || false;
diff --git a/src/serialization/sb2.js b/src/serialization/sb2.js
index 20688f35b..9669b1f5a 100644
--- a/src/serialization/sb2.js
+++ b/src/serialization/sb2.js
@@ -449,16 +449,19 @@ const parseScratchObject = function (object, runtime, extensions, topLevel, zip)
     const blockComments = {};
     if (object.hasOwnProperty('scriptComments')) {
         const comments = object.scriptComments.map(commentDesc => {
+            const isBlockComment = commentDesc[5] >= 0;
             const newComment = new Comment(
                 null, // generate a new id for this comment
                 commentDesc[6], // text content of sb2 comment
-                commentDesc[0] * 1.5, // x position of comment
-                commentDesc[1] * 2.2, // y position of comment
+                // Only serialize x & y position of comment if it's a workspace comment
+                // If it's a block comment, we'll let scratch-blocks handle positioning
+                isBlockComment ? null : commentDesc[0] * 1.5, // x position of comment
+                isBlockComment ? null : commentDesc[1] * 2.2, // y position of comment
                 commentDesc[2] * 1.5, // width of comment
                 commentDesc[3] * 2.2, // height of comment
                 !commentDesc[4] // commentDesc[4] -- false means minimized, true means full screen
             );
-            if (commentDesc[5] >= 0) {
+            if (isBlockComment) {
                 // commentDesc[5] refers to the index of the block that this
                 // comment is attached to --  in a flattened version of the
                 // scripts array.