@@ -110,7 +110,7 @@ export class TextSelectDirective implements OnInit, OnDestroy {
110110 let rangeContainer = this . getRangeContainer ( range ) ;
111111 if ( this . elementRef . nativeElement . contains ( rangeContainer ) ) {
112112 let viewportRectangle = range . getBoundingClientRect ( ) ;
113- let localRectangle = this . viewportToHost ( viewportRectangle , rangeContainer ) ;
113+ let bodyRelativeRectangle = this . rectangleRelativeToBody ( viewportRectangle , rangeContainer ) ;
114114 if ( stringSelection ) {
115115 this . zone . runGuarded ( ( ) => {
116116 this . hasSelection = true ;
@@ -127,10 +127,10 @@ export class TextSelectDirective implements OnInit, OnDestroy {
127127
128128 document . body . appendChild ( domElem ) ;
129129
130- this . componentRef . instance . rectangleLeft = localRectangle . left ;
131- this . componentRef . instance . rectangleTop = localRectangle . top ;
132- this . componentRef . instance . rectangleWidth = localRectangle . width ;
133- this . componentRef . instance . rectangleHeight = localRectangle . height ;
130+ this . componentRef . instance . elementRectangleLeft = bodyRelativeRectangle . left ;
131+ this . componentRef . instance . elementRectangleTop = bodyRelativeRectangle . top ;
132+ this . componentRef . instance . elementRectangleWidth = bodyRelativeRectangle . width ;
133+ this . componentRef . instance . elementRectangleHeight = bodyRelativeRectangle . height ;
134134 this . componentRef . instance . text = stringSelection ;
135135
136136 this . selectedText = stringSelection ;
@@ -141,12 +141,12 @@ export class TextSelectDirective implements OnInit, OnDestroy {
141141 // });
142142 }
143143
144- // Convert the given viewport-relative rectangle to a host -relative rectangle.
145- private viewportToHost (
144+ // Convert the given viewport-relative rectangle to a body -relative rectangle.
145+ private rectangleRelativeToBody (
146146 viewportRectangle : SelectionRectangle ,
147147 rangeContainer : Node
148148 ) : SelectionRectangle {
149- let host = this . elementRef . nativeElement ;
149+ let host = document . body ;
150150 let hostRectangle = host . getBoundingClientRect ( ) ;
151151 let localLeft = ( viewportRectangle . left - hostRectangle . left ) ;
152152 let localTop = ( viewportRectangle . top - hostRectangle . top ) ;
0 commit comments