Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f462eab9
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f462eab9
编写于
10月 15, 2019
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding builtin priority for custom editors
上级
89e4d3ed
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
40 addition
and
10 deletion
+40
-10
extensions/image-preview/package.json
extensions/image-preview/package.json
+1
-0
src/vs/workbench/contrib/customEditor/browser/customEditors.ts
...s/workbench/contrib/customEditor/browser/customEditors.ts
+35
-9
src/vs/workbench/contrib/customEditor/browser/extensionPoint.ts
.../workbench/contrib/customEditor/browser/extensionPoint.ts
+3
-1
src/vs/workbench/contrib/customEditor/common/customEditor.ts
src/vs/workbench/contrib/customEditor/common/customEditor.ts
+1
-0
未找到文件。
extensions/image-preview/package.json
浏览文件 @
f462eab9
...
...
@@ -24,6 +24,7 @@
{
"viewType"
:
"imagePreview.previewEditor"
,
"displayName"
:
"%webviewEditors.displayName%"
,
"priority"
:
"builtin"
,
"selector"
:
[
{
"filenamePattern"
:
"*.{jpg,jpe,jpeg,png,bmp,gif,ico,tga,webp}"
,
...
...
src/vs/workbench/contrib/customEditor/browser/customEditors.ts
浏览文件 @
f462eab9
...
...
@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
coalesce
,
distinct
}
from
'
vs/base/common/arrays
'
;
import
{
coalesce
,
distinct
,
mergeSort
,
find
}
from
'
vs/base/common/arrays
'
;
import
*
as
glob
from
'
vs/base/common/glob
'
;
import
{
UnownedDisposable
,
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
...
...
@@ -272,10 +272,19 @@ export class CustomEditorContribution implements IWorkbenchContribution {
return
;
}
const
defaultEditors
=
contributedEditors
.
filter
(
editor
=>
editor
.
priority
===
CustomEditorPriority
.
default
);
if
(
defaultEditors
.
length
===
1
)
{
// 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
s
[
0
]
.
id
,
options
,
group
),
override
:
this
.
customEditorService
.
openWith
(
resource
,
defaultEditor
.
id
,
options
,
group
),
};
}
}
...
...
@@ -326,15 +335,20 @@ export class CustomEditorContribution implements IWorkbenchContribution {
return
undefined
;
}
const
editors
=
distinct
([
...
this
.
customEditorService
.
getUserConfiguredCustomEditors
(
resource
),
...
this
.
customEditorService
.
getContributedCustomEditors
(
resource
),
],
editor
=>
editor
.
id
);
// Prefer default editors in the diff editor case but ultimatly always take the first editor
const
editors
=
mergeSort
(
distinct
([
...
this
.
customEditorService
.
getUserConfiguredCustomEditors
(
resource
),
...
this
.
customEditorService
.
getContributedCustomEditors
(
resource
),
],
editor
=>
editor
.
id
),
(
a
,
b
)
=>
{
return
priorityToRank
(
a
.
priority
)
-
priorityToRank
(
b
.
priority
);
});
if
(
!
editors
.
length
)
{
return
undefined
;
}
// Always prefer the first editor in the diff editor case
return
this
.
customEditorService
.
createInput
(
resource
,
editors
[
0
].
id
,
group
,
{
customClasses
});
};
...
...
@@ -354,6 +368,18 @@ export class CustomEditorContribution implements IWorkbenchContribution {
}
}
function
isLowerPriority
(
otherEditor
:
CustomEditorInfo
,
editor
:
CustomEditorInfo
):
unknown
{
return
priorityToRank
(
otherEditor
.
priority
)
<
priorityToRank
(
editor
.
priority
);
}
function
priorityToRank
(
priority
:
CustomEditorPriority
):
number
{
switch
(
priority
)
{
case
CustomEditorPriority
.
default
:
return
3
;
case
CustomEditorPriority
.
builtin
:
return
2
;
case
CustomEditorPriority
.
option
:
return
1
;
}
}
function
matches
(
selector
:
CustomEditorSelector
,
resource
:
URI
):
boolean
{
if
(
resource
.
scheme
===
Schemas
.
data
)
{
if
(
!
selector
.
mime
)
{
...
...
src/vs/workbench/contrib/customEditor/browser/extensionPoint.ts
浏览文件 @
f462eab9
...
...
@@ -65,11 +65,13 @@ const webviewEditorsContribution: IJSONSchema = {
description
:
nls
.
localize
(
'
contributes.priority
'
,
'
Controls when the custom editor is used. May be overridden by users.
'
),
enum
:
[
CustomEditorPriority
.
default
,
CustomEditorPriority
.
option
CustomEditorPriority
.
option
,
CustomEditorPriority
.
builtin
,
],
enumDescriptions
:
[
nls
.
localize
(
'
contributes.priority.default
'
,
'
Editor is automatically used for a resource if no other default custom editors are registered for it.
'
),
nls
.
localize
(
'
contributes.priority.option
'
,
'
Editor is not automatically used but can be selected by a user.
'
),
nls
.
localize
(
'
contributes.priority.builtin
'
,
'
Editor automatically used if no other `default` or `builtin` editors are registered for the resource.
'
),
],
default
:
'
default
'
}
...
...
src/vs/workbench/contrib/customEditor/common/customEditor.ts
浏览文件 @
f462eab9
...
...
@@ -28,6 +28,7 @@ export interface ICustomEditorService {
export
const
enum
CustomEditorPriority
{
default
=
'
default
'
,
builtin
=
'
builtin
'
,
option
=
'
option
'
,
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录