@@ -8,7 +8,7 @@ import * as nls from 'vs/nls';
88import * as dom from 'vs/base/browser/dom' ;
99import { FastDomNode , createFastDomNode } from 'vs/base/browser/fastDomNode' ;
1010import { ISashEvent , IVerticalSashLayoutProvider , Sash , SashState } from 'vs/base/browser/ui/sash/sash' ;
11- import { RunOnceScheduler } from 'vs/base/common/async' ;
11+ import { RunOnceScheduler , IntervalTimer } from 'vs/base/common/async' ;
1212import { Color } from 'vs/base/common/color' ;
1313import { Emitter , Event } from 'vs/base/common/event' ;
1414import { Disposable } from 'vs/base/common/lifecycle' ;
@@ -156,17 +156,17 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
156156 private _width : number ;
157157 private _height : number ;
158158 private _reviewHeight : number ;
159- private readonly _measureDomElementToken : number ;
159+ private readonly _measureDomElementToken : IntervalTimer | null ;
160160
161- private originalEditor : CodeEditorWidget ;
161+ private readonly originalEditor : CodeEditorWidget ;
162162 private readonly _originalDomNode : HTMLElement ;
163163 private readonly _originalEditorState : VisualEditorState ;
164- private _originalOverviewRuler : editorBrowser . IOverviewRuler ;
164+ private _originalOverviewRuler : editorBrowser . IOverviewRuler | null ;
165165
166- private modifiedEditor : CodeEditorWidget ;
166+ private readonly modifiedEditor : CodeEditorWidget ;
167167 private readonly _modifiedDomNode : HTMLElement ;
168168 private readonly _modifiedEditorState : VisualEditorState ;
169- private _modifiedOverviewRuler : editorBrowser . IOverviewRuler ;
169+ private _modifiedOverviewRuler : editorBrowser . IOverviewRuler | null ;
170170
171171 private _currentlyChangingViewZones : boolean ;
172172 private _beginUpdateDecorationsTimeout : number ;
@@ -182,7 +182,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
182182 private _renderSideBySide : boolean ;
183183 private _renderIndicators : boolean ;
184184 private _enableSplitViewResizing : boolean ;
185- private _strategy : IDiffEditorWidgetStyle ;
185+ private _strategy ! : IDiffEditorWidgetStyle ;
186186
187187 private readonly _updateDecorationsRunner : RunOnceScheduler ;
188188
@@ -308,16 +308,22 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
308308 rightServices . set ( IContextKeyService , rightContextKeyService ) ;
309309 const rightScopedInstantiationService = instantiationService . createChild ( rightServices ) ;
310310
311- this . _createLeftHandSideEditor ( options , leftScopedInstantiationService ) ;
312- this . _createRightHandSideEditor ( options , rightScopedInstantiationService ) ;
311+ this . originalEditor = this . _createLeftHandSideEditor ( options , leftScopedInstantiationService ) ;
312+ this . modifiedEditor = this . _createRightHandSideEditor ( options , rightScopedInstantiationService ) ;
313+
314+ this . _originalOverviewRuler = null ;
315+ this . _modifiedOverviewRuler = null ;
313316
314317 this . _reviewPane = new DiffReview ( this ) ;
315318 this . _containerDomElement . appendChild ( this . _reviewPane . domNode . domNode ) ;
316319 this . _containerDomElement . appendChild ( this . _reviewPane . shadow . domNode ) ;
317320 this . _containerDomElement . appendChild ( this . _reviewPane . actionBarContainer . domNode ) ;
318321
319322 if ( options . automaticLayout ) {
320- this . _measureDomElementToken = window . setInterval ( ( ) => this . _measureDomElement ( false ) , 100 ) ;
323+ this . _measureDomElementToken = new IntervalTimer ( ) ;
324+ this . _measureDomElementToken . cancelAndSet ( ( ) => this . _measureDomElement ( false ) , 100 ) ;
325+ } else {
326+ this . _measureDomElementToken = null ;
321327 }
322328
323329 // enableSplitViewResizing
@@ -397,10 +403,10 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
397403 this . _layoutOverviewRulers ( ) ;
398404 }
399405
400- private _createLeftHandSideEditor ( options : editorOptions . IDiffEditorOptions , instantiationService : IInstantiationService ) : void {
401- this . originalEditor = this . _createInnerEditor ( instantiationService , this . _originalDomNode , this . _adjustOptionsForLeftHandSide ( options , this . _originalIsEditable ) ) ;
406+ private _createLeftHandSideEditor ( options : editorOptions . IDiffEditorOptions , instantiationService : IInstantiationService ) : CodeEditorWidget {
407+ const editor = this . _createInnerEditor ( instantiationService , this . _originalDomNode , this . _adjustOptionsForLeftHandSide ( options , this . _originalIsEditable ) ) ;
402408
403- this . _register ( this . originalEditor . onDidScrollChange ( ( e ) => {
409+ this . _register ( editor . onDidScrollChange ( ( e ) => {
404410 if ( this . _isHandlingScrollEvent ) {
405411 return ;
406412 }
@@ -417,21 +423,23 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
417423 this . _layoutOverviewViewport ( ) ;
418424 } ) ) ;
419425
420- this . _register ( this . originalEditor . onDidChangeViewZones ( ( ) => {
426+ this . _register ( editor . onDidChangeViewZones ( ( ) => {
421427 this . _onViewZonesChanged ( ) ;
422428 } ) ) ;
423429
424- this . _register ( this . originalEditor . onDidChangeModelContent ( ( ) => {
430+ this . _register ( editor . onDidChangeModelContent ( ( ) => {
425431 if ( this . _isVisible ) {
426432 this . _beginUpdateDecorationsSoon ( ) ;
427433 }
428434 } ) ) ;
435+
436+ return editor ;
429437 }
430438
431- private _createRightHandSideEditor ( options : editorOptions . IDiffEditorOptions , instantiationService : IInstantiationService ) : void {
432- this . modifiedEditor = this . _createInnerEditor ( instantiationService , this . _modifiedDomNode , this . _adjustOptionsForRightHandSide ( options ) ) ;
439+ private _createRightHandSideEditor ( options : editorOptions . IDiffEditorOptions , instantiationService : IInstantiationService ) : CodeEditorWidget {
440+ const editor = this . _createInnerEditor ( instantiationService , this . _modifiedDomNode , this . _adjustOptionsForRightHandSide ( options ) ) ;
433441
434- this . _register ( this . modifiedEditor . onDidScrollChange ( ( e ) => {
442+ this . _register ( editor . onDidScrollChange ( ( e ) => {
435443 if ( this . _isHandlingScrollEvent ) {
436444 return ;
437445 }
@@ -448,21 +456,23 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
448456 this . _layoutOverviewViewport ( ) ;
449457 } ) ) ;
450458
451- this . _register ( this . modifiedEditor . onDidChangeViewZones ( ( ) => {
459+ this . _register ( editor . onDidChangeViewZones ( ( ) => {
452460 this . _onViewZonesChanged ( ) ;
453461 } ) ) ;
454462
455- this . _register ( this . modifiedEditor . onDidChangeConfiguration ( ( e ) => {
456- if ( e . fontInfo && this . modifiedEditor . getModel ( ) ) {
463+ this . _register ( editor . onDidChangeConfiguration ( ( e ) => {
464+ if ( e . fontInfo && editor . getModel ( ) ) {
457465 this . _onViewZonesChanged ( ) ;
458466 }
459467 } ) ) ;
460468
461- this . _register ( this . modifiedEditor . onDidChangeModelContent ( ( ) => {
469+ this . _register ( editor . onDidChangeModelContent ( ( ) => {
462470 if ( this . _isVisible ) {
463471 this . _beginUpdateDecorationsSoon ( ) ;
464472 }
465473 } ) ) ;
474+
475+ return editor ;
466476 }
467477
468478 protected _createInnerEditor ( instantiationService : IInstantiationService , container : HTMLElement , options : editorOptions . IEditorOptions ) : CodeEditorWidget {
@@ -477,7 +487,9 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
477487 this . _beginUpdateDecorationsTimeout = - 1 ;
478488 }
479489
480- window . clearInterval ( this . _measureDomElementToken ) ;
490+ if ( this . _measureDomElementToken ) {
491+ this . _measureDomElementToken . dispose ( ) ;
492+ }
481493
482494 this . _cleanViewZonesAndDecorations ( ) ;
483495
@@ -813,6 +825,9 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
813825 }
814826
815827 private _layoutOverviewRulers ( ) : void {
828+ if ( ! this . _originalOverviewRuler || ! this . _modifiedOverviewRuler ) {
829+ return ;
830+ }
816831 let freeSpace = DiffEditorWidget . ENTIRE_DIFF_OVERVIEW_WIDTH - 2 * DiffEditorWidget . ONE_OVERVIEW_WIDTH ;
817832 let layoutInfo = this . modifiedEditor . getLayoutInfo ( ) ;
818833 if ( layoutInfo ) {
@@ -914,7 +929,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
914929 }
915930
916931 private _updateDecorations ( ) : void {
917- if ( ! this . originalEditor . getModel ( ) || ! this . modifiedEditor . getModel ( ) ) {
932+ if ( ! this . originalEditor . getModel ( ) || ! this . modifiedEditor . getModel ( ) || ! this . _originalOverviewRuler || ! this . _modifiedOverviewRuler ) {
918933 return ;
919934 }
920935 const lineChanges = ( this . _diffComputationResult ? this . _diffComputationResult . changes : [ ] ) ;
0 commit comments