mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
Include oldCoordinate and oldContents in ws comment event serialization (#4718)
* Include oldCoordinate and oldContent in ws comment event serialization
This commit is contained in:
@@ -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_ =
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user