Skip to content

Commit

Permalink
feat: add isDeadOrDying
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Mar 18, 2024
1 parent e29e2f4 commit 7e6068c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion core/comments/rendered_workspace_comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class RenderedWorkspaceComment extends WorkspaceComment {
this.view.addOnCollapseListener(
() => void super.setCollapsed(this.view.isCollapsed()),
);
this.view.addDisposeListener(() => void this.dispose());
this.view.addDisposeListener(() => {
if (!this.isDeadOrDying()) this.dispose();
});
}

/** Sets the text of the comment. */
Expand Down Expand Up @@ -78,6 +80,7 @@ export class RenderedWorkspaceComment extends WorkspaceComment {

/** Disposes of the view. */
override dispose() {
this.disposing = true;
if (!this.view.isDeadOrDying()) this.view.dispose();
super.dispose();
}
Expand Down
14 changes: 13 additions & 1 deletion core/comments/workspace_comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export class WorkspaceComment {
private location = new Coordinate(0, 0);

/** Whether this comment has been disposed or not. */
private disposed = false;
protected disposed = false;

/** Whether this comment is being disposed or not. */
protected disposing = false;

/**
* Constructs the comment.
Expand Down Expand Up @@ -158,11 +161,20 @@ export class WorkspaceComment {

/** Disposes of this comment. */
dispose() {
this.disposing = true;
this.disposed = true;
}

/** Returns whether the comment has been disposed or not. */
isDisposed() {
return this.disposed;
}

/**
* Returns true if this comment view is currently being disposed or has
* already been disposed.
*/
isDeadOrDying(): boolean {
return this.disposing || this.disposed;
}
}

0 comments on commit 7e6068c

Please sign in to comment.