@@ -15,6 +15,7 @@ import { Schemas } from '../../base/common/network.js';
15
15
import { EditorInput } from './editor/editorInput.js' ;
16
16
import { IEditorResolverService } from '../services/editor/common/editorResolverService.js' ;
17
17
import { DEFAULT_EDITOR_ASSOCIATION } from './editor.js' ;
18
+ import { DiffEditorInput } from './editor/diffEditorInput.js' ;
18
19
19
20
//#region < --- Workbench --- >
20
21
@@ -303,13 +304,30 @@ export function applyAvailableEditorIds(contextKey: IContextKey<string>, editor:
303
304
return ;
304
305
}
305
306
306
- const editorResource = editor . resource ;
307
- if ( editorResource ?. scheme === Schemas . untitled && editor . editorId !== DEFAULT_EDITOR_ASSOCIATION . id ) {
308
- // Non text editor untitled files cannot be easily serialized between extensions
309
- // so instead we disable this context key to prevent common commands that act on the active editor
310
- contextKey . set ( '' ) ;
311
- } else {
312
- const editors = editorResource ? editorResolverService . getEditors ( editorResource ) . map ( editor => editor . id ) : [ ] ;
313
- contextKey . set ( editors . join ( ',' ) ) ;
307
+ const editors = getAvailableEditorIds ( editor , editorResolverService ) ;
308
+ contextKey . set ( editors . join ( ',' ) ) ;
309
+ }
310
+
311
+ function getAvailableEditorIds ( editor : EditorInput , editorResolverService : IEditorResolverService ) : string [ ] {
312
+ // Non text editor untitled files cannot be easily serialized between
313
+ // extensions so instead we disable this context key to prevent common
314
+ // commands that act on the active editor.
315
+ if ( editor . resource ?. scheme === Schemas . untitled && editor . editorId !== DEFAULT_EDITOR_ASSOCIATION . id ) {
316
+ return [ ] ;
317
+ }
318
+
319
+ // Diff editors. The original and modified resources of a diff editor
320
+ // *should* be the same, but calculate the set intersection just to be safe.
321
+ if ( editor instanceof DiffEditorInput ) {
322
+ const original = getAvailableEditorIds ( editor . original , editorResolverService ) ;
323
+ const modified = new Set ( getAvailableEditorIds ( editor . modified , editorResolverService ) ) ;
324
+ return original . filter ( editor => modified . has ( editor ) ) ;
325
+ }
326
+
327
+ // Normal editors.
328
+ if ( editor . resource ) {
329
+ return editorResolverService . getEditors ( editor . resource ) . map ( editor => editor . id ) ;
314
330
}
331
+
332
+ return [ ] ;
315
333
}
0 commit comments