Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle modern workspace comment events #3

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/engine/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ class Blocks {
case 'comment_create':
if (this.runtime.getEditingTarget()) {
const currTarget = this.runtime.getEditingTarget();
currTarget.createComment(e.commentId, e.blockId, e.text,
e.xy.x, e.xy.y, e.width, e.height, e.minimized);
currTarget.createComment(e.commentId, null, '',
e.json.x, e.json.y, e.json.width, e.json.height, false);

if (currTarget.comments[e.commentId].x === null &&
currTarget.comments[e.commentId].y === null) {
Expand All @@ -430,8 +430,8 @@ class Blocks {
// comments, then the auto positioning should have taken place.
// Update the x and y position of these comments to match the
// one from the event.
currTarget.comments[e.commentId].x = e.xy.x;
currTarget.comments[e.commentId].y = e.xy.y;
currTarget.comments[e.commentId].x = e.json.x;
currTarget.comments[e.commentId].y = e.json.y;
}
}
this.emitProjectChanged();
Expand All @@ -444,18 +444,7 @@ class Blocks {
return;
}
const comment = currTarget.comments[e.commentId];
const change = e.newContents_;
if (Object.prototype.hasOwnProperty.call(change, 'minimized')) {
comment.minimized = change.minimized;
}
if (Object.prototype.hasOwnProperty.call(change, 'width') &&
Object.prototype.hasOwnProperty.call(change, 'height')) {
comment.width = change.width;
comment.height = change.height;
}
if (Object.prototype.hasOwnProperty.call(change, 'text')) {
comment.text = change.text;
}
comment.text = e.newContents_;
this.emitProjectChanged();
}
break;
Expand All @@ -474,6 +463,18 @@ class Blocks {
this.emitProjectChanged();
}
break;
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.`);
return;
}
const comment = currTarget.comments[e.commentId];
comment.minimized = e.newCollapsed;
this.emitProjectChanged();
}
break;
case 'comment_delete':
if (this.runtime.getEditingTarget()) {
const currTarget = this.runtime.getEditingTarget();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}" minimized="${this.minimized}">${xmlEscape(this.text)}</comment>`;
this.blockId !== null}" collapsed="${this.minimized}">${xmlEscape(this.text)}</comment>`;
}

// TODO choose min and defaults for width and height
Expand Down