mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-02 01:22:31 -04:00
fix: handle new custom block comment events (#4)
This commit is contained in:
parent
88c097b1f2
commit
22fcd6753d
2 changed files with 23 additions and 4 deletions
src/engine
|
@ -416,10 +416,11 @@ class Blocks {
|
||||||
this.emitProjectChanged();
|
this.emitProjectChanged();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'block_comment_create':
|
||||||
case 'comment_create':
|
case 'comment_create':
|
||||||
if (this.runtime.getEditingTarget()) {
|
if (this.runtime.getEditingTarget()) {
|
||||||
const currTarget = this.runtime.getEditingTarget();
|
const currTarget = this.runtime.getEditingTarget();
|
||||||
currTarget.createComment(e.commentId, null, '',
|
currTarget.createComment(e.commentId, e.blockId, '',
|
||||||
e.json.x, e.json.y, e.json.width, e.json.height, false);
|
e.json.x, e.json.y, e.json.width, e.json.height, false);
|
||||||
|
|
||||||
if (currTarget.comments[e.commentId].x === null &&
|
if (currTarget.comments[e.commentId].x === null &&
|
||||||
|
@ -436,6 +437,7 @@ class Blocks {
|
||||||
}
|
}
|
||||||
this.emitProjectChanged();
|
this.emitProjectChanged();
|
||||||
break;
|
break;
|
||||||
|
case 'block_comment_change':
|
||||||
case 'comment_change':
|
case 'comment_change':
|
||||||
if (this.runtime.getEditingTarget()) {
|
if (this.runtime.getEditingTarget()) {
|
||||||
const currTarget = this.runtime.getEditingTarget();
|
const currTarget = this.runtime.getEditingTarget();
|
||||||
|
@ -448,11 +450,12 @@ class Blocks {
|
||||||
this.emitProjectChanged();
|
this.emitProjectChanged();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'block_comment_move':
|
||||||
case 'comment_move':
|
case 'comment_move':
|
||||||
if (this.runtime.getEditingTarget()) {
|
if (this.runtime.getEditingTarget()) {
|
||||||
const currTarget = this.runtime.getEditingTarget();
|
const currTarget = this.runtime.getEditingTarget();
|
||||||
if (currTarget && !Object.prototype.hasOwnProperty.call(currTarget.comments, e.commentId)) {
|
if (currTarget && !Object.prototype.hasOwnProperty.call(currTarget.comments, e.commentId)) {
|
||||||
log.warn(`Cannot change comment with id ${e.commentId} because it does not exist.`);
|
log.warn(`Cannot move comment with id ${e.commentId} because it does not exist.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const comment = currTarget.comments[e.commentId];
|
const comment = currTarget.comments[e.commentId];
|
||||||
|
@ -463,11 +466,12 @@ class Blocks {
|
||||||
this.emitProjectChanged();
|
this.emitProjectChanged();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'block_comment_collapse':
|
||||||
case 'comment_collapse':
|
case 'comment_collapse':
|
||||||
if (this.runtime.getEditingTarget()) {
|
if (this.runtime.getEditingTarget()) {
|
||||||
const currTarget = this.runtime.getEditingTarget();
|
const currTarget = this.runtime.getEditingTarget();
|
||||||
if (currTarget && !Object.prototype.hasOwnProperty.call(currTarget.comments, e.commentId)) {
|
if (currTarget && !Object.prototype.hasOwnProperty.call(currTarget.comments, e.commentId)) {
|
||||||
log.warn(`Cannot change comment with id ${e.commentId} because it does not exist.`);
|
log.warn(`Cannot collapse comment with id ${e.commentId} because it does not exist.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const comment = currTarget.comments[e.commentId];
|
const comment = currTarget.comments[e.commentId];
|
||||||
|
@ -475,6 +479,21 @@ class Blocks {
|
||||||
this.emitProjectChanged();
|
this.emitProjectChanged();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'block_comment_resize':
|
||||||
|
case 'comment_resize':
|
||||||
|
if (this.runtime.getEditingTarget()) {
|
||||||
|
const currTarget = this.runtime.getEditingTarget();
|
||||||
|
if (currTarget && !Object.prototype.hasOwnProperty.call(currTarget.comments, e.commentId)) {
|
||||||
|
log.warn(`Cannot resize comment with id ${e.commentId} because it does not exist.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const comment = currTarget.comments[e.commentId];
|
||||||
|
comment.width = e.newSize.width;
|
||||||
|
comment.height = e.newSize.height;
|
||||||
|
this.emitProjectChanged();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'block_comment_delete':
|
||||||
case 'comment_delete':
|
case 'comment_delete':
|
||||||
if (this.runtime.getEditingTarget()) {
|
if (this.runtime.getEditingTarget()) {
|
||||||
const currTarget = this.runtime.getEditingTarget();
|
const currTarget = this.runtime.getEditingTarget();
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Comment {
|
||||||
toXML () {
|
toXML () {
|
||||||
return `<comment id="${this.id}" x="${this.x}" y="${
|
return `<comment id="${this.id}" x="${this.x}" y="${
|
||||||
this.y}" w="${this.width}" h="${this.height}" pinned="${
|
this.y}" w="${this.width}" h="${this.height}" pinned="${
|
||||||
this.blockId !== null}" collapsed="${this.minimized}">${xmlEscape(this.text)}</comment>`;
|
!this.minimized}" collapsed="${this.minimized}">${xmlEscape(this.text)}</comment>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO choose min and defaults for width and height
|
// TODO choose min and defaults for width and height
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue