@@ -12,7 +12,7 @@ import { getZoomLevel } from 'vs/base/browser/browser';
12
12
import { FileKind } from 'vs/platform/files/common/files' ;
13
13
import { IModelService } from 'vs/editor/common/services/model' ;
14
14
import { ILanguageService } from 'vs/editor/common/languages/language' ;
15
- import { IQuickInputService , IQuickInputButton , IQuickPickItem } from 'vs/platform/quickinput/common/quickInput' ;
15
+ import { IQuickInputService , IQuickInputButton , IQuickPickItem , QuickPickInput } from 'vs/platform/quickinput/common/quickInput' ;
16
16
import { getIconClasses } from 'vs/editor/common/services/getIconClasses' ;
17
17
import { ICommandHandler } from 'vs/platform/commands/common/commands' ;
18
18
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
@@ -253,11 +253,17 @@ abstract class BaseSwitchWindow extends Action2 {
253
253
readonly windowId : number ;
254
254
}
255
255
256
- const picks : Array < IWindowPickItem > = [ ] ;
256
+ function isWindowPickItem ( candidate : unknown ) : candidate is IWindowPickItem {
257
+ const windowPickItem = candidate as IWindowPickItem | undefined ;
258
+
259
+ return typeof windowPickItem ?. windowId === 'number' ;
260
+ }
261
+
262
+ const picks : Array < QuickPickInput < IWindowPickItem > > = [ ] ;
257
263
for ( const window of mainWindows ) {
258
264
const auxiliaryWindows = mapMainWindowToAuxiliaryWindows . get ( window . id ) ;
259
265
if ( mapMainWindowToAuxiliaryWindows . size > 0 ) {
260
- picks . push ( { type : 'separator' , payload : - 1 , label : auxiliaryWindows ? localize ( 'windowGroup' , "window group" ) : undefined } as unknown as IWindowPickItem ) ;
266
+ picks . push ( { type : 'separator' , label : auxiliaryWindows ? localize ( 'windowGroup' , "window group" ) : undefined } ) ;
261
267
}
262
268
263
269
const resource = window . filename ? URI . file ( window . filename ) : isSingleFolderWorkspaceIdentifier ( window . workspace ) ? window . workspace . uri : isWorkspaceIdentifier ( window . workspace ) ? window . workspace . configPath : undefined ;
@@ -286,13 +292,27 @@ abstract class BaseSwitchWindow extends Action2 {
286
292
}
287
293
}
288
294
289
- const placeHolder = localize ( 'switchWindowPlaceHolder' , "Select a window to switch to" ) ;
290
- const autoFocusIndex = ( picks . indexOf ( picks . filter ( pick => pick . windowId === currentWindowId ) [ 0 ] ) + 1 ) % picks . length ;
291
-
292
295
const pick = await quickInputService . pick ( picks , {
293
296
contextKey : 'inWindowsPicker' ,
294
- activeItem : picks [ autoFocusIndex ] ,
295
- placeHolder,
297
+ activeItem : ( ( ) => {
298
+ for ( let i = 0 ; i < picks . length ; i ++ ) {
299
+ const pick = picks [ i ] ;
300
+ if ( isWindowPickItem ( pick ) && pick . windowId === currentWindowId ) {
301
+ let nextPick = picks [ i + 1 ] ; // try to select next window unless it's a separator
302
+ if ( isWindowPickItem ( nextPick ) ) {
303
+ return nextPick ;
304
+ }
305
+
306
+ nextPick = picks [ i + 2 ] ; // otherwise try to select the next window after the separator
307
+ if ( isWindowPickItem ( nextPick ) ) {
308
+ return nextPick ;
309
+ }
310
+ }
311
+ }
312
+
313
+ return undefined ;
314
+ } ) ( ) ,
315
+ placeHolder : localize ( 'switchWindowPlaceHolder' , "Select a window to switch to" ) ,
296
316
quickNavigate : this . isQuickNavigate ( ) ? { keybindings : keybindingService . lookupKeybindings ( this . desc . id ) } : undefined ,
297
317
hideInput : this . isQuickNavigate ( ) ,
298
318
onDidTriggerItemButton : async context => {
0 commit comments