@@ -407,7 +407,7 @@ class FastRenderedViewLine implements IRenderedViewLine {
407407 */
408408class RenderedViewLine implements IRenderedViewLine {
409409
410- public domNode : FastDomNode < HTMLElement > ;
410+ public domNode : FastDomNode < HTMLElement > | null ;
411411 public readonly input : RenderLineInput ;
412412
413413 protected readonly _characterMapping : CharacterMapping ;
@@ -420,7 +420,7 @@ class RenderedViewLine implements IRenderedViewLine {
420420 */
421421 private readonly _pixelOffsetCache : Int32Array | null ;
422422
423- constructor ( domNode : FastDomNode < HTMLElement > , renderLineInput : RenderLineInput , characterMapping : CharacterMapping , containsRTL : boolean , containsForeignElements : ForeignElementType ) {
423+ constructor ( domNode : FastDomNode < HTMLElement > | null , renderLineInput : RenderLineInput , characterMapping : CharacterMapping , containsRTL : boolean , containsForeignElements : ForeignElementType ) {
424424 this . domNode = domNode ;
425425 this . input = renderLineInput ;
426426 this . _characterMapping = characterMapping ;
@@ -439,16 +439,19 @@ class RenderedViewLine implements IRenderedViewLine {
439439
440440 // --- Reading from the DOM methods
441441
442- protected _getReadingTarget ( ) : HTMLElement {
443- return < HTMLSpanElement > this . domNode . domNode . firstChild ;
442+ protected _getReadingTarget ( myDomNode : FastDomNode < HTMLElement > ) : HTMLElement {
443+ return < HTMLSpanElement > myDomNode . domNode . firstChild ;
444444 }
445445
446446 /**
447447 * Width of the line in pixels
448448 */
449449 public getWidth ( ) : number {
450+ if ( ! this . domNode ) {
451+ return 0 ;
452+ }
450453 if ( this . _cachedWidth === - 1 ) {
451- this . _cachedWidth = this . _getReadingTarget ( ) . offsetWidth ;
454+ this . _cachedWidth = this . _getReadingTarget ( this . domNode ) . offsetWidth ;
452455 }
453456 return this . _cachedWidth ;
454457 }
@@ -464,38 +467,41 @@ class RenderedViewLine implements IRenderedViewLine {
464467 * Visible ranges for a model range
465468 */
466469 public getVisibleRangesForRange ( startColumn : number , endColumn : number , context : DomReadingContext ) : HorizontalRange [ ] | null {
470+ if ( ! this . domNode ) {
471+ return null ;
472+ }
467473 if ( this . _pixelOffsetCache !== null ) {
468474 // the text is LTR
469- const startOffset = this . _readPixelOffset ( startColumn , context ) ;
475+ const startOffset = this . _readPixelOffset ( this . domNode , startColumn , context ) ;
470476 if ( startOffset === - 1 ) {
471477 return null ;
472478 }
473479
474- const endOffset = this . _readPixelOffset ( endColumn , context ) ;
480+ const endOffset = this . _readPixelOffset ( this . domNode , endColumn , context ) ;
475481 if ( endOffset === - 1 ) {
476482 return null ;
477483 }
478484
479485 return [ new HorizontalRange ( startOffset , endOffset - startOffset ) ] ;
480486 }
481487
482- return this . _readVisibleRangesForRange ( startColumn , endColumn , context ) ;
488+ return this . _readVisibleRangesForRange ( this . domNode , startColumn , endColumn , context ) ;
483489 }
484490
485- protected _readVisibleRangesForRange ( startColumn : number , endColumn : number , context : DomReadingContext ) : HorizontalRange [ ] | null {
491+ protected _readVisibleRangesForRange ( domNode : FastDomNode < HTMLElement > , startColumn : number , endColumn : number , context : DomReadingContext ) : HorizontalRange [ ] | null {
486492 if ( startColumn === endColumn ) {
487- const pixelOffset = this . _readPixelOffset ( startColumn , context ) ;
493+ const pixelOffset = this . _readPixelOffset ( domNode , startColumn , context ) ;
488494 if ( pixelOffset === - 1 ) {
489495 return null ;
490496 } else {
491497 return [ new HorizontalRange ( pixelOffset , 0 ) ] ;
492498 }
493499 } else {
494- return this . _readRawVisibleRangesForRange ( startColumn , endColumn , context ) ;
500+ return this . _readRawVisibleRangesForRange ( domNode , startColumn , endColumn , context ) ;
495501 }
496502 }
497503
498- protected _readPixelOffset ( column : number , context : DomReadingContext ) : number {
504+ protected _readPixelOffset ( domNode : FastDomNode < HTMLElement > , column : number , context : DomReadingContext ) : number {
499505 if ( this . _characterMapping . length === 0 ) {
500506 // This line has no content
501507 if ( this . _containsForeignElements === ForeignElementType . None ) {
@@ -520,18 +526,18 @@ class RenderedViewLine implements IRenderedViewLine {
520526 return cachedPixelOffset ;
521527 }
522528
523- const result = this . _actualReadPixelOffset ( column , context ) ;
529+ const result = this . _actualReadPixelOffset ( domNode , column , context ) ;
524530 this . _pixelOffsetCache [ column ] = result ;
525531 return result ;
526532 }
527533
528- return this . _actualReadPixelOffset ( column , context ) ;
534+ return this . _actualReadPixelOffset ( domNode , column , context ) ;
529535 }
530536
531- private _actualReadPixelOffset ( column : number , context : DomReadingContext ) : number {
537+ private _actualReadPixelOffset ( domNode : FastDomNode < HTMLElement > , column : number , context : DomReadingContext ) : number {
532538 if ( this . _characterMapping . length === 0 ) {
533539 // This line has no content
534- const r = RangeUtil . readHorizontalRanges ( this . _getReadingTarget ( ) , 0 , 0 , 0 , 0 , context . clientRectDeltaLeft , context . endNode ) ;
540+ const r = RangeUtil . readHorizontalRanges ( this . _getReadingTarget ( domNode ) , 0 , 0 , 0 , 0 , context . clientRectDeltaLeft , context . endNode ) ;
535541 if ( ! r || r . length === 0 ) {
536542 return - 1 ;
537543 }
@@ -547,14 +553,14 @@ class RenderedViewLine implements IRenderedViewLine {
547553 const partIndex = CharacterMapping . getPartIndex ( partData ) ;
548554 const charOffsetInPart = CharacterMapping . getCharIndex ( partData ) ;
549555
550- const r = RangeUtil . readHorizontalRanges ( this . _getReadingTarget ( ) , partIndex , charOffsetInPart , partIndex , charOffsetInPart , context . clientRectDeltaLeft , context . endNode ) ;
556+ const r = RangeUtil . readHorizontalRanges ( this . _getReadingTarget ( domNode ) , partIndex , charOffsetInPart , partIndex , charOffsetInPart , context . clientRectDeltaLeft , context . endNode ) ;
551557 if ( ! r || r . length === 0 ) {
552558 return - 1 ;
553559 }
554560 return r [ 0 ] . left ;
555561 }
556562
557- private _readRawVisibleRangesForRange ( startColumn : number , endColumn : number , context : DomReadingContext ) : HorizontalRange [ ] | null {
563+ private _readRawVisibleRangesForRange ( domNode : FastDomNode < HTMLElement > , startColumn : number , endColumn : number , context : DomReadingContext ) : HorizontalRange [ ] | null {
558564
559565 if ( startColumn === 1 && endColumn === this . _characterMapping . length ) {
560566 // This branch helps IE with bidi text & gives a performance boost to other browsers when reading visible ranges for an entire line
@@ -570,7 +576,7 @@ class RenderedViewLine implements IRenderedViewLine {
570576 const endPartIndex = CharacterMapping . getPartIndex ( endPartData ) ;
571577 const endCharOffsetInPart = CharacterMapping . getCharIndex ( endPartData ) ;
572578
573- return RangeUtil . readHorizontalRanges ( this . _getReadingTarget ( ) , startPartIndex , startCharOffsetInPart , endPartIndex , endCharOffsetInPart , context . clientRectDeltaLeft , context . endNode ) ;
579+ return RangeUtil . readHorizontalRanges ( this . _getReadingTarget ( domNode ) , startPartIndex , startCharOffsetInPart , endPartIndex , endCharOffsetInPart , context . clientRectDeltaLeft , context . endNode ) ;
574580 }
575581
576582 /**
@@ -591,8 +597,8 @@ class RenderedViewLine implements IRenderedViewLine {
591597}
592598
593599class WebKitRenderedViewLine extends RenderedViewLine {
594- protected _readVisibleRangesForRange ( startColumn : number , endColumn : number , context : DomReadingContext ) : HorizontalRange [ ] | null {
595- const output = super . _readVisibleRangesForRange ( startColumn , endColumn , context ) ;
600+ protected _readVisibleRangesForRange ( domNode : FastDomNode < HTMLElement > , startColumn : number , endColumn : number , context : DomReadingContext ) : HorizontalRange [ ] | null {
601+ const output = super . _readVisibleRangesForRange ( domNode , startColumn , endColumn , context ) ;
596602
597603 if ( ! output || output . length === 0 || startColumn === endColumn || ( startColumn === 1 && endColumn === this . _characterMapping . length ) ) {
598604 return output ;
@@ -603,7 +609,7 @@ class WebKitRenderedViewLine extends RenderedViewLine {
603609 if ( ! this . input . containsRTL ) {
604610 // This is an attempt to patch things up
605611 // Find position of last column
606- const endPixelOffset = this . _readPixelOffset ( endColumn , context ) ;
612+ const endPixelOffset = this . _readPixelOffset ( domNode , endColumn , context ) ;
607613 if ( endPixelOffset !== - 1 ) {
608614 const lastRange = output [ output . length - 1 ] ;
609615 if ( lastRange . left < endPixelOffset ) {
@@ -624,10 +630,10 @@ const createRenderedLine: (domNode: FastDomNode<HTMLElement> | null, renderLineI
624630 return createNormalRenderedLine ;
625631} ) ( ) ;
626632
627- function createWebKitRenderedLine ( domNode : FastDomNode < HTMLElement > , renderLineInput : RenderLineInput , characterMapping : CharacterMapping , containsRTL : boolean , containsForeignElements : ForeignElementType ) : RenderedViewLine {
633+ function createWebKitRenderedLine ( domNode : FastDomNode < HTMLElement > | null , renderLineInput : RenderLineInput , characterMapping : CharacterMapping , containsRTL : boolean , containsForeignElements : ForeignElementType ) : RenderedViewLine {
628634 return new WebKitRenderedViewLine ( domNode , renderLineInput , characterMapping , containsRTL , containsForeignElements ) ;
629635}
630636
631- function createNormalRenderedLine ( domNode : FastDomNode < HTMLElement > , renderLineInput : RenderLineInput , characterMapping : CharacterMapping , containsRTL : boolean , containsForeignElements : ForeignElementType ) : RenderedViewLine {
637+ function createNormalRenderedLine ( domNode : FastDomNode < HTMLElement > | null , renderLineInput : RenderLineInput , characterMapping : CharacterMapping , containsRTL : boolean , containsForeignElements : ForeignElementType ) : RenderedViewLine {
632638 return new RenderedViewLine ( domNode , renderLineInput , characterMapping , containsRTL , containsForeignElements ) ;
633639}
0 commit comments