Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
f8c96d72
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f8c96d72
编写于
1月 17, 2020
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
untitled - clean up interfaces
上级
1a19cd4d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
53 addition
and
33 deletion
+53
-33
src/vs/workbench/services/editor/browser/editorService.ts
src/vs/workbench/services/editor/browser/editorService.ts
+12
-4
src/vs/workbench/services/untitled/common/untitledTextEditorService.ts
...nch/services/untitled/common/untitledTextEditorService.ts
+39
-27
src/vs/workbench/test/common/editor/untitledTextEditor.test.ts
...s/workbench/test/common/editor/untitledTextEditor.test.ts
+2
-2
未找到文件。
src/vs/workbench/services/editor/browser/editorService.ts
浏览文件 @
f8c96d72
...
...
@@ -610,13 +610,21 @@ export class EditorService extends Disposable implements EditorServiceImpl {
// Untitled file support
const
untitledInput
=
input
as
IUntitledTextResourceInput
;
if
(
untitledInput
.
forceUntitled
||
!
untitledInput
.
resource
||
(
untitledInput
.
resource
&&
untitledInput
.
resource
.
scheme
===
Schemas
.
untitled
))
{
return
this
.
untitledTextEditorService
.
create
({
untitledResource
:
untitledInput
.
resource
?.
scheme
===
Schemas
.
untitled
?
untitledInput
.
resource
:
undefined
,
associatedResource
:
untitledInput
.
resource
?.
scheme
!==
Schemas
.
untitled
?
untitledInput
.
resource
:
undefined
,
const
untitledOptions
=
{
mode
:
untitledInput
.
mode
,
initialValue
:
untitledInput
.
contents
,
encoding
:
untitledInput
.
encoding
});
};
// Untitled resource: use as hint for an existing untitled editor
if
(
untitledInput
.
resource
?.
scheme
===
Schemas
.
untitled
)
{
return
this
.
untitledTextEditorService
.
create
({
untitledResource
:
untitledInput
.
resource
,
...
untitledOptions
});
}
// Other resource: use as hint for associated filepath
else
{
return
this
.
untitledTextEditorService
.
create
({
associatedResource
:
untitledInput
.
resource
,
...
untitledOptions
});
}
}
// Resource Editor Support
...
...
src/vs/workbench/services/untitled/common/untitledTextEditorService.ts
浏览文件 @
f8c96d72
...
...
@@ -18,25 +18,7 @@ import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverServ
export
const
IUntitledTextEditorService
=
createDecorator
<
IUntitledTextEditorService
>
(
'
untitledTextEditorService
'
);
export
interface
IUntitledTextEditorOptions
{
/**
* An optional resource to identify the untitled resource to create or return
* if already existing.
*
* Note: the resource will not be used unless the scheme is `untitled`.
*/
untitledResource
?:
URI
;
/**
* Optional resource components to associate with the untitled file. When saving
* the untitled file, the associated components will be used and the user
* is not being asked to provide a file path.
*
* Note: currently it is not possible to specify the `scheme` to use. The
* untitled file will saved to the default local or remote resource.
*/
associatedResource
?:
{
authority
:
string
;
path
:
string
;
query
:
string
;
fragment
:
string
;
}
export
interface
INewUntitledTextEditorOptions
{
/**
* Initial value of the untitled file. An untitled file with initial
...
...
@@ -55,6 +37,32 @@ export interface IUntitledTextEditorOptions {
encoding
?:
string
;
}
export
interface
IExistingUntitledTextEditorOptions
extends
INewUntitledTextEditorOptions
{
/**
* A resource to identify the untitled resource to create or return
* if already existing.
*
* Note: the resource will not be used unless the scheme is `untitled`.
*/
untitledResource
?:
URI
;
}
export
interface
INewUntitledTextEditorWithAssociatedResourceOptions
extends
INewUntitledTextEditorOptions
{
/**
* Resource components to associate with the untitled file. When saving
* the untitled file, the associated components will be used and the user
* is not being asked to provide a file path.
*
* Note: currently it is not possible to specify the `scheme` to use. The
* untitled file will saved to the default local or remote resource.
*/
associatedResource
?:
{
authority
:
string
;
path
:
string
;
query
:
string
;
fragment
:
string
;
}
}
type
IInternalUntitledTextEditorOptions
=
IExistingUntitledTextEditorOptions
&
INewUntitledTextEditorWithAssociatedResourceOptions
;
export
interface
IUntitledTextEditorModelManager
{
/**
...
...
@@ -87,14 +95,18 @@ export interface IUntitledTextEditorModelManager {
* property is provided and the untitled input exists, it will return that existing
* instance instead of creating a new one.
*/
create
(
options
?:
IUntitledTextEditorOptions
):
UntitledTextEditorInput
;
create
(
options
?:
INewUntitledTextEditorOptions
):
UntitledTextEditorInput
;
create
(
options
?:
INewUntitledTextEditorWithAssociatedResourceOptions
):
UntitledTextEditorInput
;
create
(
options
?:
IExistingUntitledTextEditorOptions
):
UntitledTextEditorInput
;
/**
* Resolves an untitled editor model from the provided options. If the `untitledResource`
* property is provided and the untitled input exists, it will return that existing
* instance instead of creating a new one.
*/
resolve
(
options
?:
IUntitledTextEditorOptions
):
Promise
<
IUntitledTextEditorModel
&
IResolvedTextEditorModel
>
;
resolve
(
options
?:
INewUntitledTextEditorOptions
):
Promise
<
IUntitledTextEditorModel
&
IResolvedTextEditorModel
>
;
resolve
(
options
?:
INewUntitledTextEditorWithAssociatedResourceOptions
):
Promise
<
IUntitledTextEditorModel
&
IResolvedTextEditorModel
>
;
resolve
(
options
?:
IExistingUntitledTextEditorOptions
):
Promise
<
IUntitledTextEditorModel
&
IResolvedTextEditorModel
>
;
/**
* A check to find out if a untitled resource has a file path associated or not.
...
...
@@ -138,15 +150,15 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
return
this
.
mapResourceToInput
.
get
(
resource
);
}
resolve
(
options
?:
IUntitledTextEditorOptions
):
Promise
<
UntitledTextEditorModel
&
IResolvedTextEditorModel
>
{
resolve
(
options
?:
I
Internal
UntitledTextEditorOptions
):
Promise
<
UntitledTextEditorModel
&
IResolvedTextEditorModel
>
{
return
this
.
doCreateOrGet
(
options
).
resolve
();
}
create
(
options
?:
IUntitledTextEditorOptions
):
UntitledTextEditorInput
{
create
(
options
?:
I
Internal
UntitledTextEditorOptions
):
UntitledTextEditorInput
{
return
this
.
doCreateOrGet
(
options
);
}
private
doCreateOrGet
(
options
:
IUntitledTextEditorOptions
=
Object
.
create
(
null
)):
UntitledTextEditorInput
{
private
doCreateOrGet
(
options
:
I
Internal
UntitledTextEditorOptions
=
Object
.
create
(
null
)):
UntitledTextEditorInput
{
const
massagedOptions
=
this
.
massageOptions
(
options
);
// Return existing instance if asked for it
...
...
@@ -158,8 +170,8 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
return
this
.
doCreate
(
massagedOptions
);
}
private
massageOptions
(
options
:
I
UntitledTextEditorOptions
):
I
UntitledTextEditorOptions
{
const
massagedOptions
:
IUntitledTextEditorOptions
=
Object
.
create
(
null
);
private
massageOptions
(
options
:
I
InternalUntitledTextEditorOptions
):
IInternal
UntitledTextEditorOptions
{
const
massagedOptions
:
I
Internal
UntitledTextEditorOptions
=
Object
.
create
(
null
);
// Figure out associated and untitled resource
if
(
options
.
associatedResource
)
{
...
...
@@ -194,7 +206,7 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
return
massagedOptions
;
}
private
doCreate
(
options
:
IUntitledTextEditorOptions
):
UntitledTextEditorInput
{
private
doCreate
(
options
:
I
Internal
UntitledTextEditorOptions
):
UntitledTextEditorInput
{
// Create a new untitled resource if none is provided
let
untitledResource
=
options
.
untitledResource
;
...
...
src/vs/workbench/test/common/editor/untitledTextEditor.test.ts
浏览文件 @
f8c96d72
...
...
@@ -19,7 +19,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
class
ServiceAccessor
{
constructor
(
@
IUntitledTextEditorService
public
readonly
untitledTextEditorService
:
UntitledTextEditorService
,
@
IUntitledTextEditorService
public
readonly
untitledTextEditorService
:
I
UntitledTextEditorService
,
@
IEditorService
public
readonly
editorService
:
TestEditorService
,
@
IWorkingCopyService
public
readonly
workingCopyService
:
IWorkingCopyService
,
@
IModeService
public
readonly
modeService
:
ModeServiceImpl
,
...
...
@@ -38,7 +38,7 @@ suite('Workbench untitled text editors', () => {
});
teardown
(()
=>
{
accessor
.
untitledTextEditorService
.
dispose
();
(
accessor
.
untitledTextEditorService
as
UntitledTextEditorService
)
.
dispose
();
});
test
(
'
Untitled Text Editor Service
'
,
async
(
done
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录