6
6
import { localize } from 'vs/nls' ;
7
7
import { EditorGroupLayout , GroupDirection , GroupLocation , GroupOrientation , GroupsArrangement , GroupsOrder , IAuxiliaryEditorPart , IAuxiliaryEditorPartCreateEvent , IEditorDropTargetDelegate , IEditorGroupsService , IEditorSideGroup , IFindGroupScope , IMergeGroupOptions } from 'vs/workbench/services/editor/common/editorGroupsService' ;
8
8
import { Emitter } from 'vs/base/common/event' ;
9
- import { DisposableStore , IDisposable } from 'vs/base/common/lifecycle' ;
9
+ import { DisposableStore , IDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
10
10
import { GroupIdentifier } from 'vs/workbench/common/editor' ;
11
11
import { EditorPart , MainEditorPart } from 'vs/workbench/browser/parts/editor/editorPart' ;
12
12
import { IEditorGroupView , IEditorPartsView } from 'vs/workbench/browser/parts/editor/editor' ;
@@ -23,6 +23,8 @@ export class EditorParts extends MultiWindowParts<EditorPart> implements IEditor
23
23
24
24
readonly mainPart = this . _register ( this . createMainEditorPart ( ) ) ;
25
25
26
+ private readonly mostRecentActiveParts = [ this . mainPart ] ;
27
+
26
28
constructor (
27
29
@IInstantiationService private readonly instantiationService : IInstantiationService
28
30
) {
@@ -82,10 +84,13 @@ export class EditorParts extends MultiWindowParts<EditorPart> implements IEditor
82
84
83
85
private registerEditorPartListeners ( part : EditorPart , disposables : DisposableStore ) : void {
84
86
disposables . add ( part . onDidFocus ( ( ) => {
87
+ this . doUpdateMostRecentActive ( part , true ) ;
88
+
85
89
if ( this . _parts . size > 1 ) {
86
90
this . _onDidActiveGroupChange . fire ( this . activeGroup ) ; // this can only happen when we have more than 1 editor part
87
91
}
88
92
} ) ) ;
93
+ disposables . add ( toDisposable ( ( ) => this . doUpdateMostRecentActive ( part ) ) ) ;
89
94
90
95
disposables . add ( part . onDidChangeActiveGroup ( group => this . _onDidActiveGroupChange . fire ( group ) ) ) ;
91
96
disposables . add ( part . onDidAddGroup ( group => this . _onDidAddGroup . fire ( group ) ) ) ;
@@ -98,6 +103,20 @@ export class EditorParts extends MultiWindowParts<EditorPart> implements IEditor
98
103
disposables . add ( part . onDidChangeGroupLocked ( group => this . _onDidChangeGroupLocked . fire ( group ) ) ) ;
99
104
}
100
105
106
+ private doUpdateMostRecentActive ( part : EditorPart , makeMostRecentlyActive ?: boolean ) : void {
107
+ const index = this . mostRecentActiveParts . indexOf ( part ) ;
108
+
109
+ // Remove from MRU list
110
+ if ( index !== - 1 ) {
111
+ this . mostRecentActiveParts . splice ( index , 1 ) ;
112
+ }
113
+
114
+ // Add to front as needed
115
+ if ( makeMostRecentlyActive ) {
116
+ this . mostRecentActiveParts . unshift ( part ) ;
117
+ }
118
+ }
119
+
101
120
private getGroupsLabel ( index : number ) : string {
102
121
return localize ( 'groupLabel' , "Window {0}" , index + 1 ) ;
103
122
}
@@ -186,10 +205,14 @@ export class EditorParts extends MultiWindowParts<EditorPart> implements IEditor
186
205
getGroups ( order = GroupsOrder . CREATION_TIME ) : IEditorGroupView [ ] {
187
206
if ( this . _parts . size > 1 ) {
188
207
let parts : EditorPart [ ] ;
189
- if ( order === GroupsOrder . MOST_RECENTLY_ACTIVE ) {
190
- parts = distinct ( [ this . activePart , ...this . _parts ] ) ; // put active part first in this order
191
- } else {
192
- parts = this . parts ;
208
+ switch ( order ) {
209
+ case GroupsOrder . GRID_APPEARANCE : // we currently do not have a way to compute by appearance over multiple windows
210
+ case GroupsOrder . CREATION_TIME :
211
+ parts = this . parts ;
212
+ break ;
213
+ case GroupsOrder . MOST_RECENTLY_ACTIVE :
214
+ parts = distinct ( [ ...this . mostRecentActiveParts , ...this . parts ] ) ; // always ensure all parts are included
215
+ break ;
193
216
}
194
217
195
218
return parts . map ( part => part . getGroups ( order ) ) . flat ( ) ;
0 commit comments