From 62dc2ff6fa8f211710d3d82f5ab68032792bc65c Mon Sep 17 00:00:00 2001 From: Monica Kozbial Date: Mon, 22 Mar 2021 08:41:31 -0700 Subject: [PATCH] Include oldCoordinate and oldContents in ws comment event serialization (#4718) * Include oldCoordinate and oldContent in ws comment event serialization --- core/events/ws_comment_events.js | 11 +++++++++++ tests/mocha/event_test.js | 7 ++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/events/ws_comment_events.js b/core/events/ws_comment_events.js index 5bcfa4758..a77c36428 100644 --- a/core/events/ws_comment_events.js +++ b/core/events/ws_comment_events.js @@ -126,6 +126,7 @@ Blockly.Events.CommentChange.prototype.type = Blockly.Events.COMMENT_CHANGE; */ Blockly.Events.CommentChange.prototype.toJson = function() { var json = Blockly.Events.CommentChange.superClass_.toJson.call(this); + json['oldContents'] = this.oldContents_; json['newContents'] = this.newContents_; return json; }; @@ -136,6 +137,7 @@ Blockly.Events.CommentChange.prototype.toJson = function() { */ Blockly.Events.CommentChange.prototype.fromJson = function(json) { Blockly.Events.CommentChange.superClass_.fromJson.call(this, json); + this.oldContents_ = json['oldContents']; this.newContents_ = json['newContents']; }; @@ -358,6 +360,10 @@ Blockly.Events.CommentMove.prototype.setOldCoordinate = function(xy) { // TODO (#1266): "Full" and "minimal" serialization. Blockly.Events.CommentMove.prototype.toJson = function() { var json = Blockly.Events.CommentMove.superClass_.toJson.call(this); + if (this.oldCoordinate_) { + json['oldCoordinate'] = Math.round(this.oldCoordinate_.x) + ',' + + Math.round(this.oldCoordinate_.y); + } if (this.newCoordinate_) { json['newCoordinate'] = Math.round(this.newCoordinate_.x) + ',' + Math.round(this.newCoordinate_.y); @@ -372,6 +378,11 @@ Blockly.Events.CommentMove.prototype.toJson = function() { Blockly.Events.CommentMove.prototype.fromJson = function(json) { Blockly.Events.CommentMove.superClass_.fromJson.call(this, json); + if (json['oldCoordinate']) { + var xy = json['oldCoordinate'].split(','); + this.oldCoordinate_ = + new Blockly.utils.Coordinate(Number(xy[0]), Number(xy[1])); + } if (json['newCoordinate']) { var xy = json['newCoordinate'].split(','); this.newCoordinate_ = diff --git a/tests/mocha/event_test.js b/tests/mocha/event_test.js index 26e5d4a09..c53850ebb 100644 --- a/tests/mocha/event_test.js +++ b/tests/mocha/event_test.js @@ -611,9 +611,10 @@ suite('Events', function() { ]; var workspaceCommentEventTestCases = [ {title: 'Comment change', class: Blockly.Events.CommentChange, - getArgs: (thisObj) => [thisObj.comment, '', 'words'], + getArgs: (thisObj) => [thisObj.comment, 'bar', 'foo'], getExpectedJson: (thisObj) => ({type: 'comment_change', - commentId: thisObj.comment.id, newContents: 'words'})}, + commentId: thisObj.comment.id, oldContents: 'bar', + newContents: 'foo'})}, {title: 'Comment create', class: Blockly.Events.CommentCreate, getArgs: (thisObj) => [thisObj.comment], getExpectedJson: (thisObj) => ({type: 'comment_create', @@ -627,7 +628,7 @@ suite('Events', function() { {title: 'Comment move', class: Blockly.Events.CommentMove, getArgs: (thisObj) => [thisObj.comment], getExpectedJson: (thisObj) => ({type: 'comment_move', - commentId: thisObj.comment.id})}, + commentId: thisObj.comment.id, oldCoordinate: '0,0'})}, ]; var testSuites = [ {title: 'Variable events', testCases: variableEventTestCases,