diff --git a/src/vs/platform/editor/common/editor.ts b/src/vs/platform/editor/common/editor.ts index f4e2cffb761..a2ab758a208 100644 --- a/src/vs/platform/editor/common/editor.ts +++ b/src/vs/platform/editor/common/editor.ts @@ -161,12 +161,17 @@ export enum EditorOverride { /** * Displays a picker and allows the user to decide which editor to use */ - PICK = 1, + PICK, /** * Disables overrides */ - DISABLED + DISABLED, + + /** + * Only exclusive overrides are considered + */ + EXCLUSIVE_ONLY } export enum EditorOpenContext { diff --git a/src/vs/workbench/api/browser/mainThreadEditors.ts b/src/vs/workbench/api/browser/mainThreadEditors.ts index 9cf68817e11..72d97e02e7c 100644 --- a/src/vs/workbench/api/browser/mainThreadEditors.ts +++ b/src/vs/workbench/api/browser/mainThreadEditors.ts @@ -144,7 +144,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { // preserve pre 1.38 behaviour to not make group active when preserveFocus: true // but make sure to restore the editor to fix https://github.com/microsoft/vscode/issues/79633 activation: options.preserveFocus ? EditorActivation.RESTORE : undefined, - override: EditorOverride.DISABLED + override: EditorOverride.EXCLUSIVE_ONLY }; const input: IResourceEditorInput = { diff --git a/src/vs/workbench/services/editor/browser/editorOverrideService.ts b/src/vs/workbench/services/editor/browser/editorOverrideService.ts index 11dca5ecf6f..294b7752e6f 100644 --- a/src/vs/workbench/services/editor/browser/editorOverrideService.ts +++ b/src/vs/workbench/services/editor/browser/editorOverrideService.ts @@ -116,8 +116,7 @@ export class EditorOverrideService extends Disposable implements IEditorOverride } // Resolved the override as much as possible, now find a given editor - const { editor: matchededEditor, conflictingDefault } = this.getEditor(resource, override); - const selectedEditor = matchededEditor; + const { editor: selectedEditor, conflictingDefault } = this.getEditor(resource, override); if (!selectedEditor) { return OverrideStatus.NONE; } @@ -253,7 +252,7 @@ export class EditorOverrideService extends Disposable implements IEditorOverride * Given a resource and an override selects the best possible editor * @returns The editor and whether there was another default which conflicted with it */ - private getEditor(resource: URI, override: string | undefined): { editor: RegisteredEditor | undefined, conflictingDefault: boolean } { + private getEditor(resource: URI, override: string | EditorOverride.EXCLUSIVE_ONLY | undefined): { editor: RegisteredEditor | undefined, conflictingDefault: boolean } { const findMatchingEditor = (editors: RegisteredEditors, viewType: string) => { return editors.find((editor) => { if (editor.options && editor.options.canSupportResource !== undefined) { @@ -262,7 +261,7 @@ export class EditorOverrideService extends Disposable implements IEditorOverride return editor.editorInfo.id === viewType; }); }; - if (override) { + if (override && override !== EditorOverride.EXCLUSIVE_ONLY) { // Specific overried passed in doesn't have to match the resource, it can be anything const registeredEditors = this._registeredEditors; return { @@ -274,12 +273,19 @@ export class EditorOverrideService extends Disposable implements IEditorOverride let editors = this.findMatchingEditors(resource); const associationsFromSetting = this.getAssociationsForResource(resource); - // We only want built-in+ if no user defined setting is found, else we won't override - const possibleEditors = editors.filter(editor => priorityToRank(editor.editorInfo.priority) >= priorityToRank(RegisteredEditorPriority.builtin) && editor.editorInfo.id !== DEFAULT_EDITOR_ASSOCIATION.id); + // We only want minPriority+ if no user defined setting is found, else we won't override + const minPriority = override === EditorOverride.EXCLUSIVE_ONLY ? RegisteredEditorPriority.exclusive : RegisteredEditorPriority.builtin; + const possibleEditors = editors.filter(editor => priorityToRank(editor.editorInfo.priority) >= priorityToRank(minPriority) && editor.editorInfo.id !== DEFAULT_EDITOR_ASSOCIATION.id); + if (possibleEditors.length === 0) { + return { + editor: undefined, + conflictingDefault: false + }; + } // If the editor is exclusive we use that, else use the user setting, else use the built-in+ editor - const selectedViewType = possibleEditors[0]?.editorInfo.priority === RegisteredEditorPriority.exclusive ? - possibleEditors[0]?.editorInfo.id : - associationsFromSetting[0]?.viewType || possibleEditors[0]?.editorInfo.id; + const selectedViewType = possibleEditors[0].editorInfo.priority === RegisteredEditorPriority.exclusive ? + possibleEditors[0].editorInfo.id : + associationsFromSetting[0]?.viewType || possibleEditors[0].editorInfo.id; let conflictingDefault = false; if (associationsFromSetting.length === 0 && possibleEditors.length > 1) {