mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 15:02:52 -05:00
Merge pull request #1217 from kchadha/comment-state-fixes
Comment state fixes
This commit is contained in:
commit
3a61cac384
1 changed files with 12 additions and 34 deletions
|
@ -295,9 +295,8 @@ class Blocks {
|
||||||
oldInput: e.oldInputName,
|
oldInput: e.oldInputName,
|
||||||
newParent: e.newParentId,
|
newParent: e.newParentId,
|
||||||
newInput: e.newInputName,
|
newInput: e.newInputName,
|
||||||
newCoordinate: e.newCoordinate,
|
newCoordinate: e.newCoordinate
|
||||||
oldCoordinate: e.oldCoordinate
|
});
|
||||||
}, optRuntime);
|
|
||||||
break;
|
break;
|
||||||
case 'dragOutside':
|
case 'dragOutside':
|
||||||
if (optRuntime) {
|
if (optRuntime) {
|
||||||
|
@ -374,22 +373,16 @@ class Blocks {
|
||||||
}
|
}
|
||||||
const comment = currTarget.comments[e.commentId];
|
const comment = currTarget.comments[e.commentId];
|
||||||
const change = e.newContents_;
|
const change = e.newContents_;
|
||||||
if (typeof change === 'object') {
|
|
||||||
if (change.hasOwnProperty('minimized')) {
|
if (change.hasOwnProperty('minimized')) {
|
||||||
comment.minimized = change.minimized;
|
comment.minimized = change.minimized;
|
||||||
break;
|
}
|
||||||
} else if (change.hasOwnProperty('width') && change.hasOwnProperty('height')){
|
if (change.hasOwnProperty('width') && change.hasOwnProperty('height')){
|
||||||
comment.width = change.width;
|
comment.width = change.width;
|
||||||
comment.height = change.height;
|
comment.height = change.height;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else if (typeof change === 'string') {
|
if (change.hasOwnProperty('text')) {
|
||||||
comment.text = change;
|
comment.text = change.text;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
log.warn(`Unrecognized comment change: ${
|
|
||||||
JSON.stringify(change)} for comment with id: ${e.commentId}.`);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'comment_move':
|
case 'comment_move':
|
||||||
|
@ -552,10 +545,8 @@ class Blocks {
|
||||||
/**
|
/**
|
||||||
* Block management: move blocks from parent to parent
|
* Block management: move blocks from parent to parent
|
||||||
* @param {!object} e Blockly move event to be processed
|
* @param {!object} e Blockly move event to be processed
|
||||||
* @param {?Runtime} optRuntime Optional runtime for updating the position
|
|
||||||
* of a comment on the block that moved.
|
|
||||||
*/
|
*/
|
||||||
moveBlock (e, optRuntime) {
|
moveBlock (e) {
|
||||||
if (!this._blocks.hasOwnProperty(e.id)) {
|
if (!this._blocks.hasOwnProperty(e.id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -564,19 +555,6 @@ class Blocks {
|
||||||
if (e.newCoordinate) {
|
if (e.newCoordinate) {
|
||||||
this._blocks[e.id].x = e.newCoordinate.x;
|
this._blocks[e.id].x = e.newCoordinate.x;
|
||||||
this._blocks[e.id].y = e.newCoordinate.y;
|
this._blocks[e.id].y = e.newCoordinate.y;
|
||||||
|
|
||||||
// If the moved block has a comment, update the position of the comment.
|
|
||||||
if (typeof this._blocks[e.id].comment === 'string' && optRuntime &&
|
|
||||||
e.oldCoordinate) {
|
|
||||||
const commentId = this._blocks[e.id].comment;
|
|
||||||
const currTarget = optRuntime.getEditingTarget();
|
|
||||||
if (currTarget && currTarget.comments.hasOwnProperty(commentId)) {
|
|
||||||
const deltaX = e.newCoordinate.x - e.oldCoordinate.x;
|
|
||||||
const deltaY = e.newCoordinate.y - e.oldCoordinate.y;
|
|
||||||
currTarget.comments[commentId].x += deltaX;
|
|
||||||
currTarget.comments[commentId].y += deltaY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove from any old parent.
|
// Remove from any old parent.
|
||||||
|
|
Loading…
Reference in a new issue