55'use strict' ;
66
77import { EmitterEvent } from 'vs/base/common/eventEmitter' ;
8- import { IDisposable , Disposable } from 'vs/base/common/lifecycle' ;
98import * as strings from 'vs/base/common/strings' ;
109import { Position , IPosition } from 'vs/editor/common/core/position' ;
1110import { Range } from 'vs/editor/common/core/range' ;
@@ -14,10 +13,9 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
1413import { TokenizationRegistry , ColorId , LanguageId } from 'vs/editor/common/modes' ;
1514import { tokenizeLineToHTML } from 'vs/editor/common/modes/textToHtmlTokenizer' ;
1615import { ViewModelDecorations } from 'vs/editor/common/viewModel/viewModelDecorations' ;
17- import { MinimapLinesRenderingData , ViewLineRenderingData , ViewModelDecoration , IViewModelListener , IViewModel , ICoordinatesConverter , ViewEventsCollector } from 'vs/editor/common/viewModel/viewModel' ;
16+ import { MinimapLinesRenderingData , ViewLineRenderingData , ViewModelDecoration , IViewModel , ICoordinatesConverter , ViewEventsCollector } from 'vs/editor/common/viewModel/viewModel' ;
1817import { SplitLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection' ;
1918import * as viewEvents from 'vs/editor/common/view/viewEvents' ;
20- import * as errors from 'vs/base/common/errors' ;
2119import { MinimapTokensColorTracker } from 'vs/editor/common/view/minimapCharRenderer' ;
2220import * as textModelEvents from 'vs/editor/common/model/textModelEvents' ;
2321import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions' ;
@@ -85,43 +83,7 @@ export class CoordinatesConverter implements ICoordinatesConverter {
8583
8684}
8785
88- export class ViewEventEmitter extends Disposable {
89- private _listeners : IViewModelListener [ ] ;
90-
91- constructor ( ) {
92- super ( ) ;
93- this . _listeners = [ ] ;
94- }
95-
96- public dispose ( ) : void {
97- this . _listeners = [ ] ;
98- super . dispose ( ) ;
99- }
100-
101- protected _emit ( events : viewEvents . ViewEvent [ ] ) : void {
102- const listeners = this . _listeners . slice ( 0 ) ;
103- for ( let i = 0 , len = listeners . length ; i < len ; i ++ ) {
104- safeInvokeListener ( listeners [ i ] , events ) ;
105- }
106- }
107-
108- public addEventListener ( listener : ( events : viewEvents . ViewEvent [ ] ) => void ) : IDisposable {
109- this . _listeners . push ( listener ) ;
110- return {
111- dispose : ( ) => {
112- let listeners = this . _listeners ;
113- for ( let i = 0 , len = listeners . length ; i < len ; i ++ ) {
114- if ( listeners [ i ] === listener ) {
115- listeners . splice ( i , 1 ) ;
116- break ;
117- }
118- }
119- }
120- } ;
121- }
122- }
123-
124- export class ViewModel extends ViewEventEmitter implements IViewModel {
86+ export class ViewModel extends viewEvents . ViewEventEmitter implements IViewModel {
12587
12688 private readonly editorId : number ;
12789 private readonly configuration : editorCommon . IConfiguration ;
@@ -214,7 +176,8 @@ export class ViewModel extends ViewEventEmitter implements IViewModel {
214176 if ( this . lines . setWrappingSettings ( conf . wrappingInfo . wrappingIndent , conf . wrappingInfo . wrappingColumn , conf . fontInfo . typicalFullwidthCharacterWidth / conf . fontInfo . typicalHalfwidthCharacterWidth ) ) {
215177 eventsCollector . emit ( new viewEvents . ViewFlushedEvent ( ) ) ;
216178 eventsCollector . emit ( new viewEvents . ViewLineMappingChangedEvent ( ) ) ;
217- this . decorations . onLineMappingChanged ( eventsCollector ) ;
179+ eventsCollector . emit ( new viewEvents . ViewDecorationsChangedEvent ( ) ) ;
180+ this . decorations . onLineMappingChanged ( ) ;
218181 this . viewLayout . onFlushed ( this . getLineCount ( ) ) ;
219182 revealPreviousCenteredModelRange = true ;
220183 }
@@ -356,15 +319,17 @@ export class ViewModel extends ViewEventEmitter implements IViewModel {
356319 if ( this . lines . setTabSize ( this . model . getOptions ( ) . tabSize ) ) {
357320 eventsCollector . emit ( new viewEvents . ViewFlushedEvent ( ) ) ;
358321 eventsCollector . emit ( new viewEvents . ViewLineMappingChangedEvent ( ) ) ;
359- this . decorations . onLineMappingChanged ( eventsCollector ) ;
322+ eventsCollector . emit ( new viewEvents . ViewDecorationsChangedEvent ( ) ) ;
323+ this . decorations . onLineMappingChanged ( ) ;
360324 this . viewLayout . onFlushed ( this . getLineCount ( ) ) ;
361325 }
362326
363327 break ;
364328 }
365329 case textModelEvents . TextModelEventType . ModelDecorationsChanged : {
366330 const e = < textModelEvents . IModelDecorationsChangedEvent > data ;
367- this . decorations . onModelDecorationsChanged ( eventsCollector , e ) ;
331+ this . decorations . onModelDecorationsChanged ( e ) ;
332+ eventsCollector . emit ( new viewEvents . ViewDecorationsChangedEvent ( ) ) ;
368333 break ;
369334 }
370335 case textModelEvents . TextModelEventType . ModelDispose : {
@@ -379,7 +344,8 @@ export class ViewModel extends ViewEventEmitter implements IViewModel {
379344
380345 if ( ! hadOtherModelChange && hadModelLineChangeThatChangedLineMapping ) {
381346 eventsCollector . emit ( new viewEvents . ViewLineMappingChangedEvent ( ) ) ;
382- this . decorations . onLineMappingChanged ( eventsCollector ) ;
347+ eventsCollector . emit ( new viewEvents . ViewDecorationsChangedEvent ( ) ) ;
348+ this . decorations . onLineMappingChanged ( ) ;
383349 }
384350 }
385351
@@ -389,7 +355,8 @@ export class ViewModel extends ViewEventEmitter implements IViewModel {
389355 if ( lineMappingChanged ) {
390356 eventsCollector . emit ( new viewEvents . ViewFlushedEvent ( ) ) ;
391357 eventsCollector . emit ( new viewEvents . ViewLineMappingChangedEvent ( ) ) ;
392- this . decorations . onLineMappingChanged ( eventsCollector ) ;
358+ eventsCollector . emit ( new viewEvents . ViewDecorationsChangedEvent ( ) ) ;
359+ this . decorations . onLineMappingChanged ( ) ;
393360 this . viewLayout . onFlushed ( this . getLineCount ( ) ) ;
394361 }
395362 this . _emit ( eventsCollector . finalize ( ) ) ;
@@ -623,11 +590,3 @@ export class ViewModel extends ViewEventEmitter implements IViewModel {
623590 return result ;
624591 }
625592}
626-
627- function safeInvokeListener ( listener : IViewModelListener , events : viewEvents . ViewEvent [ ] ) : void {
628- try {
629- listener ( events ) ;
630- } catch ( e ) {
631- errors . onUnexpectedError ( e ) ;
632- }
633- }
0 commit comments