@@ -319,9 +319,9 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
319
319
const cursor = this . state . editor . getPosition ( ) ;
320
320
if ( cursor ) {
321
321
const top = this . state . editor . getTopForPosition ( cursor . lineNumber , cursor . column ) ;
322
- const lines = this . getVisibleLines ( ) ;
323
- const lineTops = lines . length === this . lineTops . length ? this . lineTops : this . computeLineTops ( ) ;
324
- for ( let i = 0 ; i < lines . length ; i += 1 ) {
322
+ const count = this . getVisibleLineCount ( ) ;
323
+ const lineTops = count === this . lineTops . length ? this . lineTops : this . computeLineTops ( ) ;
324
+ for ( let i = 0 ; i < count ; i += 1 ) {
325
325
if ( top <= lineTops [ i ] ) {
326
326
return i ;
327
327
}
@@ -347,10 +347,12 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
347
347
348
348
private computeLineTops ( ) : number [ ] {
349
349
const lines = this . getVisibleLines ( ) ;
350
+
351
+ // Lines are not sorted by monaco, so we have to sort them by their top value
350
352
this . lineTops = lines . map ( l => {
351
353
const match = l . style . top ? / ( .+ ) p x / . exec ( l . style . top ) : null ;
352
354
return match ? parseInt ( match [ 0 ] , 10 ) : Infinity ;
353
- } ) ;
355
+ } ) . sort ( ( a , b ) => a - b ) ;
354
356
return this . lineTops ;
355
357
}
356
358
@@ -359,7 +361,6 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
359
361
const visibleLineDivs = this . getVisibleLines ( ) ;
360
362
const current = this . getCurrentVisibleLine ( ) ;
361
363
if ( current !== undefined && current >= 0 ) {
362
- window . console . log ( `Scrolling to line ${ current } ` ) ;
363
364
visibleLineDivs [ current ] . scrollIntoView ( { behavior : 'auto' , block : 'nearest' , inline : 'nearest' } ) ;
364
365
}
365
366
}
0 commit comments