3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { DisposableStore } from 'vs/base/common/lifecycle' ;
7
- import { ExtHostContext , IExtHostEditorTabsShape , MainContext , IEditorTabDto , IEditorTabGroupDto , MainThreadEditorTabsShape , AnyInputDto , TabInputKind , TabModelOperationKind , TextDiffInputDto } from 'vs/workbench/api/common/extHost.protocol' ;
8
- import { extHostNamedCustomer , IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers' ;
6
+ import { Event } from 'vs/base/common/event' ;
7
+ import { DisposableMap , DisposableStore } from 'vs/base/common/lifecycle' ;
8
+ import { isEqual } from 'vs/base/common/resources' ;
9
+ import { URI } from 'vs/base/common/uri' ;
10
+ import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
11
+ import { ILogService } from 'vs/platform/log/common/log' ;
12
+ import { AnyInputDto , ExtHostContext , IEditorTabDto , IEditorTabGroupDto , IExtHostEditorTabsShape , MainContext , MainThreadEditorTabsShape , TabInputKind , TabModelOperationKind , TextDiffInputDto } from 'vs/workbench/api/common/extHost.protocol' ;
9
13
import { EditorResourceAccessor , GroupModelChangeKind , SideBySideEditor } from 'vs/workbench/common/editor' ;
10
14
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput' ;
15
+ import { isGroupEditorMoveEvent } from 'vs/workbench/common/editor/editorGroupModel' ;
11
16
import { EditorInput } from 'vs/workbench/common/editor/editorInput' ;
12
- import { columnToEditorGroup , EditorGroupColumn , editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn' ;
13
- import { GroupDirection , IEditorGroup , IEditorGroupsService , preferredSideBySideGroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService' ;
14
- import { IEditorsChangeEvent , IEditorService , SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService' ;
17
+ import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput' ;
15
18
import { AbstractTextResourceEditorInput } from 'vs/workbench/common/editor/textResourceEditorInput' ;
16
- import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput ' ;
19
+ import { ChatEditorInput } from 'vs/workbench/contrib/chat/browser/chatEditorInput ' ;
17
20
import { CustomEditorInput } from 'vs/workbench/contrib/customEditor/browser/customEditorInput' ;
18
- import { URI } from 'vs/base/common/uri' ;
19
- import { WebviewInput } from 'vs/workbench/contrib/webviewPanel/browser/webviewEditorInput' ;
20
- import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput' ;
21
- import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
22
- import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput' ;
23
- import { isEqual } from 'vs/base/common/resources' ;
24
- import { isGroupEditorMoveEvent } from 'vs/workbench/common/editor/editorGroupModel' ;
25
21
import { InteractiveEditorInput } from 'vs/workbench/contrib/interactive/browser/interactiveEditorInput' ;
26
22
import { MergeEditorInput } from 'vs/workbench/contrib/mergeEditor/browser/mergeEditorInput' ;
27
- import { ILogService } from 'vs/platform/log/common/log' ;
28
- import { ChatEditorInput } from 'vs/workbench/contrib/chat/browser/chatEditorInput' ;
29
23
import { MultiDiffEditorInput } from 'vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditorInput' ;
24
+ import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput' ;
25
+ import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput' ;
26
+ import { WebviewInput } from 'vs/workbench/contrib/webviewPanel/browser/webviewEditorInput' ;
27
+ import { columnToEditorGroup , EditorGroupColumn , editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn' ;
28
+ import { GroupDirection , IEditorGroup , IEditorGroupsService , preferredSideBySideGroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService' ;
29
+ import { IEditorsChangeEvent , IEditorService , SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService' ;
30
+ import { extHostNamedCustomer , IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers' ;
30
31
31
32
interface TabInfo {
32
33
tab : IEditorTabDto ;
@@ -44,6 +45,8 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
44
45
private readonly _groupLookup : Map < number , IEditorTabGroupDto > = new Map ( ) ;
45
46
// Lookup table for finding tab by id
46
47
private readonly _tabInfoLookup : Map < string , TabInfo > = new Map ( ) ;
48
+ // Tracks the currently open MultiDiffEditorInputs to listen to resource changes
49
+ private readonly _multiDiffEditorInputListeners : DisposableMap < MultiDiffEditorInput > = new DisposableMap ( ) ;
47
50
48
51
constructor (
49
52
extHostContext : IExtHostContext ,
@@ -65,6 +68,8 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
65
68
}
66
69
} ) ) ;
67
70
71
+ this . _dispoables . add ( this . _multiDiffEditorInputListeners ) ;
72
+
68
73
// Structural group changes (add, remove, move, etc) are difficult to patch.
69
74
// Since they happen infrequently we just rebuild the entire model
70
75
this . _dispoables . add ( this . _editorGroupsService . onDidAddGroup ( ( ) => this . _createTabsModel ( ) ) ) ;
@@ -201,7 +206,7 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
201
206
202
207
if ( editor instanceof MultiDiffEditorInput ) {
203
208
const diffEditors : TextDiffInputDto [ ] = [ ] ;
204
- for ( const resource of ( editor ?. initialResources ?? [ ] ) ) {
209
+ for ( const resource of ( editor ?. resources . get ( ) ?? [ ] ) ) {
205
210
if ( resource . original && resource . modified ) {
206
211
diffEditors . push ( {
207
212
kind : TabInputKind . TextDiffInput ,
@@ -297,7 +302,24 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
297
302
const tabObject = this . _buildTabObject ( group , editorInput , editorIndex ) ;
298
303
tabs . splice ( editorIndex , 0 , tabObject ) ;
299
304
// Update lookup
300
- this . _tabInfoLookup . set ( this . _generateTabId ( editorInput , groupId ) , { group, editorInput, tab : tabObject } ) ;
305
+ const tabId = this . _generateTabId ( editorInput , groupId ) ;
306
+ this . _tabInfoLookup . set ( tabId , { group, editorInput, tab : tabObject } ) ;
307
+
308
+ if ( editorInput instanceof MultiDiffEditorInput ) {
309
+ this . _multiDiffEditorInputListeners . set ( editorInput , Event . fromObservableLight ( editorInput . resources ) ( ( ) => {
310
+ const tabInfo = this . _tabInfoLookup . get ( tabId ) ;
311
+ if ( ! tabInfo ) {
312
+ return ;
313
+ }
314
+ tabInfo . tab = this . _buildTabObject ( group , editorInput , editorIndex ) ;
315
+ this . _proxy . $acceptTabOperation ( {
316
+ groupId,
317
+ index : editorIndex ,
318
+ tabDto : tabInfo . tab ,
319
+ kind : TabModelOperationKind . TAB_UPDATE
320
+ } ) ;
321
+ } ) ) ;
322
+ }
301
323
302
324
this . _proxy . $acceptTabOperation ( {
303
325
groupId,
@@ -331,6 +353,10 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
331
353
// Update lookup
332
354
this . _tabInfoLookup . delete ( removedTab [ 0 ] ?. id ?? '' ) ;
333
355
356
+ if ( removedTab [ 0 ] ?. input instanceof MultiDiffEditorInput ) {
357
+ this . _multiDiffEditorInputListeners . deleteAndDispose ( removedTab [ 0 ] ?. input ) ;
358
+ }
359
+
334
360
this . _proxy . $acceptTabOperation ( {
335
361
groupId,
336
362
index : editorIndex ,
0 commit comments