Skip to content

Commit

Permalink
fix: comment change events
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Mar 20, 2024
1 parent eda60ae commit 68128cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 11 additions & 0 deletions core/comments/workspace_comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,20 @@ export class WorkspaceComment {
}
}

/** Fires a comment change event. */
private fireChangeEvent(oldText: string, newText: string) {
if (eventUtils.isEnabled()) {
eventUtils.fire(
new (eventUtils.get(eventUtils.COMMENT_CHANGE))(this, oldText, newText),
);
}
}

/** Sets the text of the comment. */
setText(text: string) {
const oldText = this.text;
this.text = text;
this.fireChangeEvent(oldText, text);
}

/** Returns the text of the comment. */
Expand Down
9 changes: 6 additions & 3 deletions core/events/events_comment_change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ export class CommentChange extends CommentBase {
'the constructor, or call fromJson',
);
}
const comment = workspace.getCommentById(this.commentId);
// TODO: Remove the cast when we fix the type of getCommentById.
const comment = workspace.getCommentById(
this.commentId,
) as unknown as WorkspaceComment;
if (!comment) {
console.warn("Can't change non-existent comment: " + this.commentId);
return;
}
const contents = forward ? this.newContents_ : this.oldContents_;
if (!contents) {
if (contents === undefined) {
if (forward) {
throw new Error(
'The new contents is undefined. Either pass a value to ' +
Expand All @@ -142,7 +145,7 @@ export class CommentChange extends CommentBase {
'the constructor, or call fromJson',
);
}
comment.setContent(contents);
comment.setText(contents);
}
}

Expand Down

0 comments on commit 68128cb

Please sign in to comment.