Context key availableEditorIds for diff editors (#250198)

This commit is contained in:
Ethan Reesor
2025-07-10 10:39:47 +00:00
committed by GitHub
parent 8ce742c788
commit 5d2088c19d
+26 -8
View File
@@ -15,6 +15,7 @@ import { Schemas } from '../../base/common/network.js';
import { EditorInput } from './editor/editorInput.js';
import { IEditorResolverService } from '../services/editor/common/editorResolverService.js';
import { DEFAULT_EDITOR_ASSOCIATION } from './editor.js';
import { DiffEditorInput } from './editor/diffEditorInput.js';
//#region < --- Workbench --- >
@@ -303,13 +304,30 @@ export function applyAvailableEditorIds(contextKey: IContextKey<string>, editor:
return;
}
const editorResource = editor.resource;
if (editorResource?.scheme === Schemas.untitled && editor.editorId !== DEFAULT_EDITOR_ASSOCIATION.id) {
// Non text editor untitled files cannot be easily serialized between extensions
// so instead we disable this context key to prevent common commands that act on the active editor
contextKey.set('');
} else {
const editors = editorResource ? editorResolverService.getEditors(editorResource).map(editor => editor.id) : [];
contextKey.set(editors.join(','));
const editors = getAvailableEditorIds(editor, editorResolverService);
contextKey.set(editors.join(','));
}
function getAvailableEditorIds(editor: EditorInput, editorResolverService: IEditorResolverService): string[] {
// Non text editor untitled files cannot be easily serialized between
// extensions so instead we disable this context key to prevent common
// commands that act on the active editor.
if (editor.resource?.scheme === Schemas.untitled && editor.editorId !== DEFAULT_EDITOR_ASSOCIATION.id) {
return [];
}
// Diff editors. The original and modified resources of a diff editor
// *should* be the same, but calculate the set intersection just to be safe.
if (editor instanceof DiffEditorInput) {
const original = getAvailableEditorIds(editor.original, editorResolverService);
const modified = new Set(getAvailableEditorIds(editor.modified, editorResolverService));
return original.filter(editor => modified.has(editor));
}
// Normal editors.
if (editor.resource) {
return editorResolverService.getEditors(editor.resource).map(editor => editor.id);
}
return [];
}