提交 90163547 编写于 作者: M Matt Bierner

Refactoring onResourceEditorOpening

上级 f2220106
......@@ -8,7 +8,6 @@ import * as glob from 'vs/base/common/glob';
import { UnownedDisposable, Disposable } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { basename, DataUri, isEqual } from 'vs/base/common/resources';
import { withNullAsUndefined } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { generateUuid } from 'vs/base/common/uuid';
import * as nls from 'vs/nls';
......@@ -276,45 +275,33 @@ export class CustomEditorContribution implements IWorkbenchContribution {
group: IEditorGroup
): IOpenEditorOverride | undefined {
const userConfiguredEditors = this.customEditorService.getUserConfiguredCustomEditors(resource);
const contributedEditors = this.customEditorService.getContributedCustomEditors(resource);
if (!userConfiguredEditors.length) {
if (!contributedEditors.length) {
return;
}
// Find the single default editor to use (if any) by looking at the editor's priority and the
// other contributed editors.
const defaultEditor = find(contributedEditors, editor => {
if (editor.priority !== CustomEditorPriority.default && editor.priority !== CustomEditorPriority.builtin) {
return false;
}
return contributedEditors.every(otherEditor =>
otherEditor === editor || isLowerPriority(otherEditor, editor));
});
if (defaultEditor) {
return {
override: this.customEditorService.openWith(resource, defaultEditor.id, options, group),
};
}
if (userConfiguredEditors.length) {
return {
override: this.customEditorService.openWith(resource, userConfiguredEditors[0].id, options, group),
};
}
for (const input of group.editors) {
if (input instanceof CustomFileEditorInput && isEqual(input.getResource(), resource)) {
return {
override: group.openEditor(input, options).then(withNullAsUndefined)
};
}
const contributedEditors = this.customEditorService.getContributedCustomEditors(resource);
if (!contributedEditors.length) {
return;
}
if (userConfiguredEditors.length) {
// Find the single default editor to use (if any) by looking at the editor's priority and the
// other contributed editors.
const defaultEditor = find(contributedEditors, editor => {
if (editor.priority !== CustomEditorPriority.default && editor.priority !== CustomEditorPriority.builtin) {
return false;
}
return contributedEditors.every(otherEditor =>
otherEditor === editor || isLowerPriority(otherEditor, editor));
});
if (defaultEditor) {
return {
override: this.customEditorService.openWith(resource, userConfiguredEditors[0].id, options, group),
override: this.customEditorService.openWith(resource, defaultEditor.id, options, group),
};
}
// Open default editor but prompt user to see if they wish to use a custom one instead
// Open VS Code's standard editor but prompt user to see if they wish to use a custom one instead
return {
override: (async () => {
const standardEditor = await this.editorService.openEditor(editor, { ...options, ignoreOverrides: true }, group);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册