@@ -9,7 +9,7 @@ import { ContentWidgetPositionPreference, IContentWidget } from 'vs/editor/brows
9
9
import { PartFingerprint , PartFingerprints , ViewPart } from 'vs/editor/browser/view/viewPart' ;
10
10
import { IRange , Range } from 'vs/editor/common/core/range' ;
11
11
import { Constants } from 'vs/base/common/uint' ;
12
- import { RenderingContext , RestrictedRenderingContext } from 'vs/editor/browser/view/renderingContext' ;
12
+ import { HorizontalRange , LineVisibleRanges , RenderingContext , RestrictedRenderingContext } from 'vs/editor/browser/view/renderingContext' ;
13
13
import { ViewContext } from 'vs/editor/common/viewModel/viewContext' ;
14
14
import * as viewEvents from 'vs/editor/common/viewEvents' ;
15
15
import { ViewportData } from 'vs/editor/common/viewLayout/viewLinesViewportData' ;
@@ -404,54 +404,42 @@ class Widget {
404
404
/**
405
405
* Compute `this._topLeft`
406
406
*/
407
- private _getTopAndBottomLeft ( ctx : RenderingContext ) : [ Coordinate , Coordinate ] | [ null , null ] {
407
+ private _getTopAndBottomLeft ( 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
- if ( ! visibleRangesForRange || visibleRangesForRange . length === 0 ) {
414
- return [ null , null ] ;
415
- }
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 ) ;
416
415
417
- let firstLine = visibleRangesForRange [ 0 ] ;
418
- let lastLine = visibleRangesForRange [ 0 ] ;
419
- for ( const visibleRangesForLine of visibleRangesForRange ) {
420
- if ( visibleRangesForLine . lineNumber < firstLine . lineNumber ) {
421
- firstLine = visibleRangesForLine ;
422
- }
423
- if ( visibleRangesForLine . lineNumber > lastLine . lineNumber ) {
424
- lastLine = visibleRangesForLine ;
425
- }
426
- }
416
+ return [ topLeft , bottomLeft ] ;
427
417
428
- let firstLineMinLeft = Constants . MAX_SAFE_SMALL_INTEGER ; //firstLine.Constants.MAX_SAFE_SMALL_INTEGER;
429
- for ( const visibleRange of firstLine . ranges ) {
430
- if ( visibleRange . left < firstLineMinLeft ) {
431
- firstLineMinLeft = visibleRange . left ;
418
+ function getCoordinate ( line : LineVisibleRanges | null , affinity : PositionAffinity | null , startColumn : number , deltaTop : number ) : Coordinate | null {
419
+ if ( ! line ) {
420
+ return null ;
432
421
}
433
- }
434
-
435
- // Left-align widgets that should appear :before content
436
- if ( this . _affinity === PositionAffinity . LeftOfInjectedText &&
437
- this . _viewRange . startColumn === 1 ) {
438
- firstLineMinLeft = 0 ;
439
- }
440
-
441
- let lastLineMinLeft = Constants . MAX_SAFE_SMALL_INTEGER ; //lastLine.Constants.MAX_SAFE_SMALL_INTEGER;
442
- for ( const visibleRange of lastLine . ranges ) {
443
- if ( visibleRange . left < lastLineMinLeft ) {
444
- lastLineMinLeft = visibleRange . left ;
422
+ const left = getLeft ( line . ranges , affinity , startColumn ) ;
423
+ const top = ctx . getVerticalOffsetForLineNumber ( line . lineNumber ) - ctx . scrollTop ;
424
+ return new Coordinate ( top + deltaTop , left ) ;
425
+ }
426
+
427
+ /**
428
+ * Return the left-most position from `ranges`.
429
+ */
430
+ function getLeft ( ranges : HorizontalRange [ ] , affinity : PositionAffinity | null , startColumn : number ) : number {
431
+ // Left-align widgets that should appear :before content
432
+ if ( startColumn === 1 && affinity === PositionAffinity . LeftOfInjectedText ) {
433
+ return 0 ;
434
+ }
435
+ let result = Constants . MAX_SAFE_SMALL_INTEGER ;
436
+ for ( const range of ranges ) {
437
+ if ( range . left < result ) {
438
+ result = range . left ;
439
+ }
445
440
}
441
+ return result ;
446
442
}
447
-
448
- const topForPosition = ctx . getVerticalOffsetForLineNumber ( firstLine . lineNumber ) - ctx . scrollTop ;
449
- const topLeft = new Coordinate ( topForPosition , firstLineMinLeft ) ;
450
-
451
- const topForBottomLine = ctx . getVerticalOffsetForLineNumber ( lastLine . lineNumber ) - ctx . scrollTop ;
452
- const bottomLeft = new Coordinate ( topForBottomLine + this . _lineHeight , lastLineMinLeft ) ;
453
-
454
- return [ topLeft , bottomLeft ] ;
455
443
}
456
444
457
445
private _prepareRenderWidget ( ctx : RenderingContext ) : IRenderData | null {
0 commit comments