@@ -26,6 +26,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments
2626 private _workspaceProviders = new Map < number , IDisposable > ( ) ;
2727 private _firstSessionStart : boolean ;
2828
29+ private _visibleModels : { [ key /** editor widget id */ : string ] : string /** model id */ } ;
2930 constructor (
3031 extHostContext : IExtHostContext ,
3132 @IEditorService private _editorService : IEditorService ,
@@ -36,14 +37,41 @@ export class MainThreadComments extends Disposable implements MainThreadComments
3637 super ( ) ;
3738 this . _disposables = [ ] ;
3839 this . _firstSessionStart = true ;
40+ this . _visibleModels = { } ;
3941 this . _proxy = extHostContext . getProxy ( ExtHostContext . ExtHostComments ) ;
40- this . _disposables . push ( this . _editorService . onDidActiveEditorChange ( e => {
42+ this . _disposables . push ( this . _editorService . onDidVisibleEditorsChange ( e => {
4143 const editors = this . getFocusedEditors ( ) ;
44+ const visibleEditors = this . getVisibleEditors ( ) ;
45+
46+ const _visibleEditors = { } ;
47+ visibleEditors . forEach ( editor => {
48+ const id = editor . getId ( ) ;
49+ if ( editors . filter ( ed => ed . getId ( ) === id ) . length > 0 ) {
50+ // it's an active editor, we are going to update this editor's comments anyways
51+ } else {
52+ if ( this . _visibleModels [ id ] ) {
53+ // it's the same active editor, but we may want to check if the model is still the same
54+ let modelId = editor . getModel ( ) . getModeId ( ) ;
55+ if ( modelId !== this . _visibleModels [ id ] ) {
56+ editors . push ( editor ) ;
57+ }
58+ } else {
59+ // update
60+ editors . push ( editor ) ;
61+ }
62+ }
63+
64+ _visibleEditors [ id ] = editor . getModel ( ) . getModeId ( ) ;
65+ } ) ;
66+
67+ this . _visibleModels = _visibleEditors ;
68+
4269 if ( ! editors || ! editors . length ) {
4370 return ;
4471 }
4572
4673 editors . forEach ( editor => {
74+ console . log ( editor . getId ( ) ) ;
4775 const controller = ReviewController . get ( editor ) ;
4876 if ( ! controller ) {
4977 return ;
@@ -119,12 +147,21 @@ export class MainThreadComments extends Disposable implements MainThreadComments
119147 this . _commentService . updateComments ( event ) ;
120148 }
121149
122- dispose ( ) : void {
123- this . _disposables = dispose ( this . _disposables ) ;
124- this . _workspaceProviders . forEach ( value => dispose ( value ) ) ;
125- this . _workspaceProviders . clear ( ) ;
126- this . _documentProviders . forEach ( value => dispose ( value ) ) ;
127- this . _documentProviders . clear ( ) ;
150+ getVisibleEditors ( ) : ICodeEditor [ ] {
151+ let ret = [ ] ;
152+
153+ this . _editorService . visibleControls . forEach ( control => {
154+ if ( isCodeEditor ( control . getControl ( ) ) ) {
155+ ret . push ( control . getControl ( ) as ICodeEditor ) ;
156+ }
157+
158+ if ( isDiffEditor ( control . getControl ( ) ) ) {
159+ let diffEditor = control . getControl ( ) as IDiffEditor ;
160+ ret . push ( diffEditor . getOriginalEditor ( ) , diffEditor . getModifiedEditor ( ) ) ;
161+ }
162+ } ) ;
163+
164+ return ret ;
128165 }
129166
130167 getFocusedEditors ( ) : ICodeEditor [ ] {
@@ -163,4 +200,13 @@ export class MainThreadComments extends Disposable implements MainThreadComments
163200 }
164201 return result ;
165202 }
203+
204+ dispose ( ) : void {
205+ this . _disposables = dispose ( this . _disposables ) ;
206+ this . _workspaceProviders . forEach ( value => dispose ( value ) ) ;
207+ this . _workspaceProviders . clear ( ) ;
208+ this . _documentProviders . forEach ( value => dispose ( value ) ) ;
209+ this . _documentProviders . clear ( ) ;
210+ this . _visibleModels = { } ;
211+ }
166212}
0 commit comments