Skip to content

Commit 2d2ebfd

Browse files
authored
fix: line authoring crashes when dom Element cannot be removed. (#891)
* fix: line authoring crashes when dom Element cannot be removed. * fix: format
1 parent f653019 commit 2d2ebfd

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/lineAuthor/view/gutter/gutter.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ export class TextGutter extends GutterMarker {
5555
}
5656

5757
destroy(dom: HTMLElement): void {
58-
if (!document.body.contains(dom)) dom.remove();
58+
if (!dom) {
59+
return; // sometimes, it doesn't exist anymore.
60+
}
61+
62+
if (!document.body.contains(dom)) {
63+
dom.remove();
64+
}
5965
}
6066
}
6167

@@ -115,10 +121,14 @@ export class LineAuthoringGutter extends GutterMarker {
115121
}
116122

117123
public destroy(dom: HTMLElement): void {
124+
if (!dom) {
125+
return; // sometimes, it doesn't exist anymore.
126+
}
127+
118128
// this is called frequently, when the gutter moves outside of the view.
119129
if (!document.body.contains(dom)) {
120-
dom.remove();
121130
attachedGutterElements.delete(dom);
131+
dom.remove();
122132
}
123133
}
124134

0 commit comments

Comments
 (0)