@@ -119,6 +119,7 @@ export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestr
119119 protected items : SequenceItemInfo [ ] = [ ] ;
120120 protected hasFocus = false ;
121121 protected selection = 0 ;
122+ protected setupComplete = false ;
122123
123124 public displayState = 'normal' ;
124125
@@ -183,6 +184,23 @@ export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestr
183184
184185 ngAfterViewInit ( ) : void {
185186 this . canvas = this . canvasRef . nativeElement ;
187+
188+ if ( document . body . contains ( this . canvas ) )
189+ this . setup ( ) ;
190+ else {
191+ const observer = new MutationObserver ( ( ) => {
192+ if ( document . body . contains ( this . canvas ) ) {
193+ observer . disconnect ( ) ;
194+ this . setup ( ) ;
195+ }
196+ } ) ;
197+
198+ observer . observe ( document . body , { childList : true , subtree : true } ) ;
199+ }
200+ }
201+
202+ private setup ( ) : void {
203+ this . canvas = this . canvasRef . nativeElement ;
186204 this . font = getFont ( this . canvas ) ;
187205
188206 this . smallFont = this . fixedFont = this . smallFixedFont = this . font ;
@@ -233,6 +251,7 @@ export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestr
233251 this . canvas . contentEditable = 'false' ;
234252
235253 this . computeSize ( ) ;
254+ this . setupComplete = true ;
236255 this . draw ( ) ;
237256 }
238257
@@ -310,7 +329,7 @@ export class KsSequenceEditorComponent implements AfterViewInit, OnInit, OnDestr
310329 }
311330
312331 protected draw ( ) : void {
313- if ( ! this . canvas )
332+ if ( ! this . canvas || ! this . setupComplete )
314333 return ;
315334
316335 const padding = KsSequenceEditorComponent . getPadding ( this . metrics ) ;
0 commit comments