mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Track block comment movement when block moves.
This commit is contained in:
parent
7c5a2ae8e0
commit
644fab0135
1 changed files with 19 additions and 3 deletions
|
@ -295,8 +295,9 @@ class Blocks {
|
|||
oldInput: e.oldInputName,
|
||||
newParent: e.newParentId,
|
||||
newInput: e.newInputName,
|
||||
newCoordinate: e.newCoordinate
|
||||
});
|
||||
newCoordinate: e.newCoordinate,
|
||||
oldCoordinate: e.oldCoordinate
|
||||
}, optRuntime);
|
||||
break;
|
||||
case 'dragOutside':
|
||||
if (optRuntime) {
|
||||
|
@ -551,8 +552,10 @@ class Blocks {
|
|||
/**
|
||||
* Block management: move blocks from parent to parent
|
||||
* @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) {
|
||||
moveBlock (e, optRuntime) {
|
||||
if (!this._blocks.hasOwnProperty(e.id)) {
|
||||
return;
|
||||
}
|
||||
|
@ -561,6 +564,19 @@ class Blocks {
|
|||
if (e.newCoordinate) {
|
||||
this._blocks[e.id].x = e.newCoordinate.x;
|
||||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue