fix: handle new custom block comment events ()

This commit is contained in:
Aaron Dodson 2024-07-09 09:31:31 -07:00 committed by GitHub
parent 88c097b1f2
commit 22fcd6753d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 4 deletions

View file

@ -416,10 +416,11 @@ class Blocks {
this.emitProjectChanged();
break;
}
case 'block_comment_create':
case 'comment_create':
if (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);
if (currTarget.comments[e.commentId].x === null &&
@ -436,6 +437,7 @@ class Blocks {
}
this.emitProjectChanged();
break;
case 'block_comment_change':
case 'comment_change':
if (this.runtime.getEditingTarget()) {
const currTarget = this.runtime.getEditingTarget();
@ -448,11 +450,12 @@ class Blocks {
this.emitProjectChanged();
}
break;
case 'block_comment_move':
case 'comment_move':
if (this.runtime.getEditingTarget()) {
const currTarget = this.runtime.getEditingTarget();
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;
}
const comment = currTarget.comments[e.commentId];
@ -463,11 +466,12 @@ class Blocks {
this.emitProjectChanged();
}
break;
case 'block_comment_collapse':
case 'comment_collapse':
if (this.runtime.getEditingTarget()) {
const currTarget = this.runtime.getEditingTarget();
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;
}
const comment = currTarget.comments[e.commentId];
@ -475,6 +479,21 @@ class Blocks {
this.emitProjectChanged();
}
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':
if (this.runtime.getEditingTarget()) {
const currTarget = this.runtime.getEditingTarget();

View file

@ -31,7 +31,7 @@ class Comment {
toXML () {
return `<comment id="${this.id}" x="${this.x}" y="${
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