Include oldCoordinate and oldContents in ws comment event serialization (#4718)

* Include oldCoordinate and oldContent in ws comment event serialization
This commit is contained in:
Monica Kozbial
2021-03-22 08:41:31 -07:00
committed by GitHub
parent a6a34f9311
commit 62dc2ff6fa
2 changed files with 15 additions and 3 deletions

View File

@@ -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_ =

View File

@@ -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,