diff --git a/src/engine/blocks.js b/src/engine/blocks.js index f9d0138c808..ebee6427cf5 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -419,8 +419,8 @@ class Blocks { case 'comment_create': if (this.runtime.getEditingTarget()) { const currTarget = this.runtime.getEditingTarget(); - currTarget.createComment(e.commentId, e.blockId, e.text, - e.xy.x, e.xy.y, e.width, e.height, e.minimized); + currTarget.createComment(e.commentId, null, '', + e.json.x, e.json.y, e.json.width, e.json.height, false); if (currTarget.comments[e.commentId].x === null && currTarget.comments[e.commentId].y === null) { @@ -430,8 +430,8 @@ class Blocks { // comments, then the auto positioning should have taken place. // Update the x and y position of these comments to match the // one from the event. - currTarget.comments[e.commentId].x = e.xy.x; - currTarget.comments[e.commentId].y = e.xy.y; + currTarget.comments[e.commentId].x = e.json.x; + currTarget.comments[e.commentId].y = e.json.y; } } this.emitProjectChanged(); @@ -444,18 +444,7 @@ class Blocks { return; } const comment = currTarget.comments[e.commentId]; - const change = e.newContents_; - if (Object.prototype.hasOwnProperty.call(change, 'minimized')) { - comment.minimized = change.minimized; - } - if (Object.prototype.hasOwnProperty.call(change, 'width') && - Object.prototype.hasOwnProperty.call(change, 'height')) { - comment.width = change.width; - comment.height = change.height; - } - if (Object.prototype.hasOwnProperty.call(change, 'text')) { - comment.text = change.text; - } + comment.text = e.newContents_; this.emitProjectChanged(); } break; @@ -474,6 +463,18 @@ class Blocks { this.emitProjectChanged(); } break; + case 'comment_collapse': + if (this.runtime.getEditingTarget()) { + const currTarget = this.runtime.getEditingTarget(); + if (currTarget && !Object.prototype.hasOwnProperty.call(currTarget.comments, e.commentId)) { + log.warn(`Cannot change comment with id ${e.commentId} because it does not exist.`); + return; + } + const comment = currTarget.comments[e.commentId]; + comment.minimized = e.newCollapsed; + this.emitProjectChanged(); + } + break; case 'comment_delete': if (this.runtime.getEditingTarget()) { const currTarget = this.runtime.getEditingTarget(); diff --git a/src/engine/comment.js b/src/engine/comment.js index ac644e770ea..bdf4e8f893a 100644 --- a/src/engine/comment.js +++ b/src/engine/comment.js @@ -31,7 +31,7 @@ class Comment { toXML () { return `${xmlEscape(this.text)}`; + this.blockId !== null}" collapsed="${this.minimized}">${xmlEscape(this.text)}`; } // TODO choose min and defaults for width and height