Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
502f5a57
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,体验更适合开发者的 AI 搜索 >>
提交
502f5a57
编写于
1月 17, 2020
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
untitled - some
💄
上级
b135faa0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
31 addition
and
41 deletion
+31
-41
src/vs/workbench/services/editor/browser/editorService.ts
src/vs/workbench/services/editor/browser/editorService.ts
+6
-1
src/vs/workbench/services/textfile/browser/textFileService.ts
...vs/workbench/services/textfile/browser/textFileService.ts
+10
-14
src/vs/workbench/services/untitled/common/untitledTextEditorService.ts
...nch/services/untitled/common/untitledTextEditorService.ts
+9
-20
src/vs/workbench/test/common/editor/untitledTextEditor.test.ts
...s/workbench/test/common/editor/untitledTextEditor.test.ts
+6
-6
未找到文件。
src/vs/workbench/services/editor/browser/editorService.ts
浏览文件 @
502f5a57
...
...
@@ -610,7 +610,12 @@ 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
(
untitledInput
.
resource
,
untitledInput
.
mode
,
untitledInput
.
contents
,
untitledInput
.
encoding
);
return
this
.
untitledTextEditorService
.
create
({
resource
:
untitledInput
.
resource
,
mode
:
untitledInput
.
mode
,
initialValue
:
untitledInput
.
contents
,
encoding
:
untitledInput
.
encoding
});
}
// Resource Editor Support
...
...
src/vs/workbench/services/textfile/browser/textFileService.ts
浏览文件 @
502f5a57
...
...
@@ -53,9 +53,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
readonly
files
=
this
.
_register
(
this
.
instantiationService
.
createInstance
(
TextFileEditorModelManager
));
private
_untitled
:
IUntitledTextEditorModelManager
;
get
untitled
():
IUntitledTextEditorModelManager
{
return
this
.
_untitled
;
}
get
untitled
():
IUntitledTextEditorModelManager
{
return
this
.
_untitled
;
}
abstract
get
encoding
():
IResourceEncodings
;
...
...
@@ -179,7 +177,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
await
this
.
_onWillRunOperation
.
fireAsync
({
operation
:
FileOperation
.
DELETE
,
target
:
resource
},
CancellationToken
.
None
);
const
dirtyFiles
=
this
.
getDirtyFileModels
().
map
(
dirtyFileModel
=>
dirtyFileModel
.
resource
).
filter
(
dirty
=>
isEqualOrParent
(
dirty
,
resource
));
await
this
.
doRevert
All
Files
(
dirtyFiles
,
{
soft
:
true
});
await
this
.
doRevertFiles
(
dirtyFiles
,
{
soft
:
true
});
await
this
.
fileService
.
del
(
resource
,
options
);
...
...
@@ -245,7 +243,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
// in order to move and copy, we need to soft revert all dirty models,
// both from the source as well as the target if any
const
dirtyModels
=
[...
sourceModels
,
...
conflictingModels
].
filter
(
model
=>
model
.
isDirty
());
await
this
.
doRevert
All
Files
(
dirtyModels
.
map
(
dirtyModel
=>
dirtyModel
.
resource
),
{
soft
:
true
});
await
this
.
doRevertFiles
(
dirtyModels
.
map
(
dirtyModel
=>
dirtyModel
.
resource
),
{
soft
:
true
});
// now we can rename the source to target via file operation
let
stat
:
IFileStatWithMetadata
;
...
...
@@ -341,20 +339,18 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
return
this
.
fileDialogService
.
pickFileToSave
(
defaultUri
,
availableFileSystems
);
}
private
getFileModels
(
arg1
?:
URI
|
URI
[]):
ITextFileEditorModel
[]
{
if
(
Array
.
isArray
(
arg1
))
{
private
getFileModels
(
resources
?:
URI
|
URI
[]):
ITextFileEditorModel
[]
{
if
(
Array
.
isArray
(
resources
))
{
const
models
:
ITextFileEditorModel
[]
=
[];
arg1
.
forEach
(
resource
=>
{
models
.
push
(...
this
.
getFileModels
(
resource
));
});
resources
.
forEach
(
resource
=>
models
.
push
(...
this
.
getFileModels
(
resource
)));
return
models
;
}
return
this
.
files
.
getAll
(
arg1
);
return
this
.
files
.
getAll
(
resources
);
}
private
getDirtyFileModels
(
resources
?:
URI
|
URI
[]):
ITextFileEditorModel
[]
{
private
getDirtyFileModels
(
resources
?:
URI
[]):
ITextFileEditorModel
[]
{
return
this
.
getFileModels
(
resources
).
filter
(
model
=>
model
.
isDirty
());
}
...
...
@@ -576,10 +572,10 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
}
// File
return
!
(
await
this
.
doRevert
All
Files
([
resource
],
options
)).
results
.
some
(
result
=>
result
.
error
);
return
!
(
await
this
.
doRevertFiles
([
resource
],
options
)).
results
.
some
(
result
=>
result
.
error
);
}
private
async
doRevert
All
Files
(
resources
:
URI
[],
options
?:
IRevertOptions
):
Promise
<
ITextFileOperationResult
>
{
private
async
doRevertFiles
(
resources
:
URI
[],
options
?:
IRevertOptions
):
Promise
<
ITextFileOperationResult
>
{
const
fileModels
=
options
?.
force
?
this
.
getFileModels
(
resources
)
:
this
.
getDirtyFileModels
(
resources
);
const
mapResourceToResult
=
new
ResourceMap
<
IResult
>
();
...
...
src/vs/workbench/services/untitled/common/untitledTextEditorService.ts
浏览文件 @
502f5a57
...
...
@@ -18,7 +18,7 @@ import type { IResolvedTextEditorModel } from 'vs/editor/common/services/resolve
export
const
IUntitledTextEditorService
=
createDecorator
<
IUntitledTextEditorService
>
(
'
untitledTextEditorService
'
);
export
interface
IUntitled
Creation
Options
{
export
interface
IUntitled
TextEditor
Options
{
resource
?:
URI
;
mode
?:
string
;
initialValue
?:
string
;
...
...
@@ -54,20 +54,15 @@ export interface IUntitledTextEditorModelManager {
get
(
resource
:
URI
):
UntitledTextEditorInput
|
undefined
;
/**
* Creates a new untitled input with the optional resource URI to
* be used as associated file path when saving.
* Creates a new untitled input with the provided options.
*/
create
(
options
?:
IUntitledCreationOptions
):
UntitledTextEditorInput
;
create
(
resource
?:
URI
,
mode
?:
string
,
initialValue
?:
string
,
encoding
?:
string
,
hasAssociatedFilePath
?:
boolean
):
UntitledTextEditorInput
;
create
(
options
?:
IUntitledTextEditorOptions
):
UntitledTextEditorInput
;
/**
* Creates a new untitled model with the optional resource URI or returns an existing one
* if the provided resource exists already as untitled model.
*
* It is valid to pass in a file resource. In that case the path will be used as identifier.
* The use case is to be able to create a new file with a specific path with VSCode.
* Resolves an untitled editor model from the provided options. This can either
* return a new or existing model based on the options provided.
*/
resolve
(
options
?:
IUntitled
Creation
Options
):
Promise
<
IUntitledTextEditorModel
&
IResolvedTextEditorModel
>
;
resolve
(
options
?:
IUntitled
TextEditor
Options
):
Promise
<
IUntitledTextEditorModel
&
IResolvedTextEditorModel
>
;
/**
* A check to find out if a untitled resource has a file path associated or not.
...
...
@@ -112,14 +107,8 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
return
this
.
mapResourceToInput
.
get
(
resource
);
}
create
(
options
?:
IUntitledCreationOptions
):
UntitledTextEditorInput
;
create
(
resource
?:
URI
,
mode
?:
string
,
initialValue
?:
string
,
encoding
?:
string
,
hasAssociatedFilePath
?:
boolean
):
UntitledTextEditorInput
;
create
(
resourceOrOptions
?:
URI
|
IUntitledCreationOptions
,
mode
?:
string
,
initialValue
?:
string
,
encoding
?:
string
,
hasAssociatedFilePath
:
boolean
=
false
):
UntitledTextEditorInput
{
if
(
resourceOrOptions
&&
!
URI
.
isUri
(
resourceOrOptions
))
{
return
this
.
doCreateOrGet
(
resourceOrOptions
.
resource
,
resourceOrOptions
.
mode
,
resourceOrOptions
.
initialValue
,
resourceOrOptions
.
encoding
,
resourceOrOptions
.
useResourcePath
);
}
return
this
.
doCreateOrGet
(
resourceOrOptions
,
mode
,
initialValue
,
encoding
,
hasAssociatedFilePath
);
create
(
options
?:
IUntitledTextEditorOptions
):
UntitledTextEditorInput
{
return
this
.
doCreateOrGet
(
options
?.
resource
,
options
?.
mode
,
options
?.
initialValue
,
options
?.
encoding
,
options
?.
useResourcePath
);
}
private
doCreateOrGet
(
resource
?:
URI
,
mode
?:
string
,
initialValue
?:
string
,
encoding
?:
string
,
hasAssociatedFilePath
:
boolean
=
false
):
UntitledTextEditorInput
{
...
...
@@ -189,7 +178,7 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
return
input
;
}
resolve
(
options
?:
IUntitled
Creation
Options
):
Promise
<
UntitledTextEditorModel
&
IResolvedTextEditorModel
>
{
resolve
(
options
?:
IUntitled
TextEditor
Options
):
Promise
<
UntitledTextEditorModel
&
IResolvedTextEditorModel
>
{
return
this
.
doCreateOrGet
(
options
?.
resource
,
options
?.
mode
,
options
?.
initialValue
,
options
?.
encoding
,
options
?.
useResourcePath
).
resolve
();
}
...
...
src/vs/workbench/test/common/editor/untitledTextEditor.test.ts
浏览文件 @
502f5a57
...
...
@@ -46,7 +46,7 @@ suite('Workbench untitled text editors', () => {
const
workingCopyService
=
accessor
.
workingCopyService
;
const
input1
=
service
.
create
();
assert
.
equal
(
input1
,
service
.
create
(
input1
.
getResource
()
));
assert
.
equal
(
input1
,
service
.
create
(
{
resource
:
input1
.
getResource
()
}
));
assert
.
equal
(
service
.
get
(
input1
.
getResource
()),
input1
);
assert
.
ok
(
service
.
exists
(
input1
.
getResource
()));
...
...
@@ -109,7 +109,7 @@ suite('Workbench untitled text editors', () => {
test
(
'
Untitled with associated resource is dirty
'
,
()
=>
{
const
service
=
accessor
.
untitledTextEditorService
;
const
file
=
URI
.
file
(
join
(
'
C:
\\
'
,
'
/foo/file.txt
'
));
const
untitled
=
service
.
create
(
file
);
const
untitled
=
service
.
create
(
{
resource
:
file
}
);
assert
.
ok
(
service
.
hasAssociatedFilePath
(
untitled
.
getResource
()));
assert
.
equal
(
untitled
.
isDirty
(),
true
);
...
...
@@ -177,7 +177,7 @@ suite('Workbench untitled text editors', () => {
test
(
'
Untitled with associated path remains dirty when content gets empty
'
,
async
()
=>
{
const
service
=
accessor
.
untitledTextEditorService
;
const
file
=
URI
.
file
(
join
(
'
C:
\\
'
,
'
/foo/file.txt
'
));
const
input
=
service
.
create
(
file
);
const
input
=
service
.
create
(
{
resource
:
file
}
);
// dirty
const
model
=
await
input
.
resolve
();
...
...
@@ -193,7 +193,7 @@ suite('Workbench untitled text editors', () => {
const
service
=
accessor
.
untitledTextEditorService
;
const
workingCopyService
=
accessor
.
workingCopyService
;
const
untitled
=
service
.
create
(
undefined
,
undefined
,
'
Hello World
'
);
const
untitled
=
service
.
create
(
{
initialValue
:
'
Hello World
'
}
);
assert
.
equal
(
untitled
.
isDirty
(),
true
);
let
onDidChangeDirty
:
IWorkingCopy
|
undefined
=
undefined
;
...
...
@@ -251,7 +251,7 @@ suite('Workbench untitled text editors', () => {
config
.
setUserConfiguration
(
'
files
'
,
{
'
defaultLanguage
'
:
defaultLanguage
});
const
service
=
accessor
.
untitledTextEditorService
;
const
input
=
service
.
create
(
null
!
,
mode
);
const
input
=
service
.
create
(
{
mode
}
);
assert
.
equal
(
input
.
getMode
(),
mode
);
...
...
@@ -268,7 +268,7 @@ suite('Workbench untitled text editors', () => {
});
const
service
=
accessor
.
untitledTextEditorService
;
const
input
=
service
.
create
(
null
!
,
mode
);
const
input
=
service
.
create
(
{
mode
}
);
assert
.
equal
(
input
.
getMode
(),
mode
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录