@@ -292,25 +292,25 @@ class Widget {
292
292
this . _cachedDomNodeOffsetHeight = - 1 ;
293
293
}
294
294
295
- private _layoutBoxInViewport ( topLeft : Coordinate , bottomLeft : Coordinate , width : number , height : number , ctx : RenderingContext ) : IBoxLayoutResult {
295
+ private _layoutBoxInViewport ( aboveAnchor : Coordinate , belowAnchor : Coordinate , width : number , height : number , ctx : RenderingContext ) : IBoxLayoutResult {
296
296
// Our visible box is split horizontally by the current line => 2 boxes
297
297
298
298
// a) the box above the line
299
- const aboveLineTop = topLeft . top ;
300
- const heightAboveLine = aboveLineTop ;
299
+ const aboveLineTop = aboveAnchor . top ;
300
+ const heightAvailableAboveLine = aboveLineTop ;
301
301
302
302
// b) the box under the line
303
- const underLineTop = bottomLeft . top ;
304
- const heightUnderLine = ctx . viewportHeight - underLineTop ;
303
+ const underLineTop = belowAnchor . top ;
304
+ const heightAvailableUnderLine = ctx . viewportHeight - underLineTop ;
305
305
306
306
const aboveTop = aboveLineTop - height ;
307
- const fitsAbove = ( heightAboveLine >= height ) ;
307
+ const fitsAbove = ( heightAvailableAboveLine >= height ) ;
308
308
const belowTop = underLineTop ;
309
- const fitsBelow = ( heightUnderLine >= height ) ;
309
+ const fitsBelow = ( heightAvailableUnderLine >= height ) ;
310
310
311
311
// And its left
312
- let actualAboveLeft = topLeft . left ;
313
- let actualBelowLeft = bottomLeft . left ;
312
+ let actualAboveLeft = aboveAnchor . left ;
313
+ let actualBelowLeft = belowAnchor . left ;
314
314
if ( actualAboveLeft + width > ctx . scrollLeft + ctx . viewportWidth ) {
315
315
actualAboveLeft = ctx . scrollLeft + ctx . viewportWidth - width ;
316
316
}
@@ -357,17 +357,17 @@ class Widget {
357
357
return [ left , absoluteLeft ] ;
358
358
}
359
359
360
- private _layoutBoxInPage ( topLeft : Coordinate , bottomLeft : Coordinate , width : number , height : number , ctx : RenderingContext ) : IBoxLayoutResult | null {
361
- const aboveTop = topLeft . top - height ;
362
- const belowTop = bottomLeft . top ;
360
+ private _layoutBoxInPage ( aboveAnchor : Coordinate , belowAnchor : Coordinate , width : number , height : number , ctx : RenderingContext ) : IBoxLayoutResult | null {
361
+ const aboveTop = aboveAnchor . top - height ;
362
+ const belowTop = belowAnchor . top ;
363
363
364
364
const domNodePosition = dom . getDomNodePagePosition ( this . _viewDomNode . domNode ) ;
365
365
const absoluteAboveTop = domNodePosition . top + aboveTop - window . scrollY ;
366
366
const absoluteBelowTop = domNodePosition . top + belowTop - window . scrollY ;
367
367
368
368
const windowSize = dom . getClientArea ( document . body ) ;
369
- const [ aboveLeft , absoluteAboveLeft ] = this . _layoutHorizontalSegmentInPage ( windowSize , domNodePosition , topLeft . left - ctx . scrollLeft + this . _contentLeft , width ) ;
370
- const [ belowLeft , absoluteBelowLeft ] = this . _layoutHorizontalSegmentInPage ( windowSize , domNodePosition , bottomLeft . left - ctx . scrollLeft + this . _contentLeft , width ) ;
369
+ const [ aboveLeft , absoluteAboveLeft ] = this . _layoutHorizontalSegmentInPage ( windowSize , domNodePosition , aboveAnchor . left - ctx . scrollLeft + this . _contentLeft , width ) ;
370
+ const [ belowLeft , absoluteBelowLeft ] = this . _layoutHorizontalSegmentInPage ( windowSize , domNodePosition , belowAnchor . left - ctx . scrollLeft + this . _contentLeft , width ) ;
371
371
372
372
// Leave some clearance to the top/bottom
373
373
const TOP_PADDING = 22 ;
@@ -389,7 +389,7 @@ class Widget {
389
389
390
390
return {
391
391
fitsAbove,
392
- aboveTop : aboveTop ,
392
+ aboveTop,
393
393
aboveLeft,
394
394
fitsBelow,
395
395
belowTop,
@@ -402,18 +402,17 @@ class Widget {
402
402
}
403
403
404
404
/**
405
- * Compute `this._topLeft`
405
+ * Compute the above and below anchors
406
406
*/
407
- private _getTopAndBottomLeft ( ctx : RenderingContext ) : [ Coordinate | null , Coordinate | null ] {
407
+ private _getAnchors ( ctx : RenderingContext ) : [ Coordinate | null , Coordinate | null ] {
408
408
if ( ! this . _viewRange ) {
409
409
return [ null , null ] ;
410
410
}
411
411
412
412
const visibleRangesForRange = ctx . linesVisibleRangesForRange ( this . _viewRange , false ) ;
413
- const topLeft = getCoordinate ( LineVisibleRanges . firstLine ( visibleRangesForRange ) , this . _affinity , this . _viewRange . startColumn , 0 ) ;
414
- const bottomLeft = getCoordinate ( LineVisibleRanges . lastLine ( visibleRangesForRange ) , this . _affinity , this . _viewRange . startColumn , this . _lineHeight ) ;
415
-
416
- return [ topLeft , bottomLeft ] ;
413
+ const aboveAnchor = getCoordinate ( LineVisibleRanges . firstLine ( visibleRangesForRange ) , this . _affinity , this . _viewRange . startColumn , 0 ) ;
414
+ const belowAnchor = getCoordinate ( LineVisibleRanges . lastLine ( visibleRangesForRange ) , this . _affinity , this . _viewRange . startColumn , this . _lineHeight ) ;
415
+ return [ aboveAnchor , belowAnchor ] ;
417
416
418
417
function getCoordinate ( line : LineVisibleRanges | null , affinity : PositionAffinity | null , startColumn : number , deltaTop : number ) : Coordinate | null {
419
418
if ( ! line ) {
@@ -447,8 +446,8 @@ class Widget {
447
446
return null ;
448
447
}
449
448
450
- const [ topLeft , bottomLeft ] = this . _getTopAndBottomLeft ( ctx ) ;
451
- if ( ! topLeft || ! bottomLeft ) {
449
+ const [ aboveAnchor , belowAnchor ] = this . _getAnchors ( ctx ) ;
450
+ if ( ! aboveAnchor || ! belowAnchor ) {
452
451
return null ;
453
452
}
454
453
@@ -471,9 +470,9 @@ class Widget {
471
470
472
471
let placement : IBoxLayoutResult | null ;
473
472
if ( this . allowEditorOverflow ) {
474
- placement = this . _layoutBoxInPage ( topLeft , bottomLeft , this . _cachedDomNodeOffsetWidth , this . _cachedDomNodeOffsetHeight , ctx ) ;
473
+ placement = this . _layoutBoxInPage ( aboveAnchor , belowAnchor , this . _cachedDomNodeOffsetWidth , this . _cachedDomNodeOffsetHeight , ctx ) ;
475
474
} else {
476
- placement = this . _layoutBoxInViewport ( topLeft , bottomLeft , this . _cachedDomNodeOffsetWidth , this . _cachedDomNodeOffsetHeight , ctx ) ;
475
+ placement = this . _layoutBoxInViewport ( aboveAnchor , belowAnchor , this . _cachedDomNodeOffsetWidth , this . _cachedDomNodeOffsetHeight , ctx ) ;
477
476
}
478
477
479
478
// Do two passes, first for perfect fit, second picks first option
@@ -498,9 +497,9 @@ class Widget {
498
497
}
499
498
} else {
500
499
if ( this . allowEditorOverflow ) {
501
- return { coordinate : this . _prepareRenderWidgetAtExactPositionOverflowing ( topLeft ) , position : ContentWidgetPositionPreference . EXACT } ;
500
+ return { coordinate : this . _prepareRenderWidgetAtExactPositionOverflowing ( aboveAnchor ) , position : ContentWidgetPositionPreference . EXACT } ;
502
501
} else {
503
- return { coordinate : topLeft , position : ContentWidgetPositionPreference . EXACT } ;
502
+ return { coordinate : aboveAnchor , position : ContentWidgetPositionPreference . EXACT } ;
504
503
}
505
504
}
506
505
}
0 commit comments