Skip to content

Commit 9016354

Browse files
committed
Refactoring onResourceEditorOpening
1 parent f222010 commit 9016354

1 file changed

Lines changed: 19 additions & 32 deletions

File tree

src/vs/workbench/contrib/customEditor/browser/customEditors.ts

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as glob from 'vs/base/common/glob';
88
import { UnownedDisposable, Disposable } from 'vs/base/common/lifecycle';
99
import { Schemas } from 'vs/base/common/network';
1010
import { basename, DataUri, isEqual } from 'vs/base/common/resources';
11-
import { withNullAsUndefined } from 'vs/base/common/types';
1211
import { URI } from 'vs/base/common/uri';
1312
import { generateUuid } from 'vs/base/common/uuid';
1413
import * as nls from 'vs/nls';
@@ -276,45 +275,33 @@ export class CustomEditorContribution implements IWorkbenchContribution {
276275
group: IEditorGroup
277276
): IOpenEditorOverride | undefined {
278277
const userConfiguredEditors = this.customEditorService.getUserConfiguredCustomEditors(resource);
279-
const contributedEditors = this.customEditorService.getContributedCustomEditors(resource);
280-
281-
if (!userConfiguredEditors.length) {
282-
if (!contributedEditors.length) {
283-
return;
284-
}
285-
286-
// Find the single default editor to use (if any) by looking at the editor's priority and the
287-
// other contributed editors.
288-
const defaultEditor = find(contributedEditors, editor => {
289-
if (editor.priority !== CustomEditorPriority.default && editor.priority !== CustomEditorPriority.builtin) {
290-
return false;
291-
}
292-
return contributedEditors.every(otherEditor =>
293-
otherEditor === editor || isLowerPriority(otherEditor, editor));
294-
});
295-
296-
if (defaultEditor) {
297-
return {
298-
override: this.customEditorService.openWith(resource, defaultEditor.id, options, group),
299-
};
300-
}
278+
if (userConfiguredEditors.length) {
279+
return {
280+
override: this.customEditorService.openWith(resource, userConfiguredEditors[0].id, options, group),
281+
};
301282
}
302283

303-
for (const input of group.editors) {
304-
if (input instanceof CustomFileEditorInput && isEqual(input.getResource(), resource)) {
305-
return {
306-
override: group.openEditor(input, options).then(withNullAsUndefined)
307-
};
308-
}
284+
const contributedEditors = this.customEditorService.getContributedCustomEditors(resource);
285+
if (!contributedEditors.length) {
286+
return;
309287
}
310288

311-
if (userConfiguredEditors.length) {
289+
// Find the single default editor to use (if any) by looking at the editor's priority and the
290+
// other contributed editors.
291+
const defaultEditor = find(contributedEditors, editor => {
292+
if (editor.priority !== CustomEditorPriority.default && editor.priority !== CustomEditorPriority.builtin) {
293+
return false;
294+
}
295+
return contributedEditors.every(otherEditor =>
296+
otherEditor === editor || isLowerPriority(otherEditor, editor));
297+
});
298+
if (defaultEditor) {
312299
return {
313-
override: this.customEditorService.openWith(resource, userConfiguredEditors[0].id, options, group),
300+
override: this.customEditorService.openWith(resource, defaultEditor.id, options, group),
314301
};
315302
}
316303

317-
// Open default editor but prompt user to see if they wish to use a custom one instead
304+
// Open VS Code's standard editor but prompt user to see if they wish to use a custom one instead
318305
return {
319306
override: (async () => {
320307
const standardEditor = await this.editorService.openEditor(editor, { ...options, ignoreOverrides: true }, group);

0 commit comments

Comments
 (0)