Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
bb71a2ea
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,发现更多精彩内容 >>
提交
bb71a2ea
编写于
12月 28, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - avoid stringeditormodel for untitled
上级
19b321ba
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
15 deletion
+28
-15
src/vs/workbench/common/editor/untitledEditorModel.ts
src/vs/workbench/common/editor/untitledEditorModel.ts
+23
-10
src/vs/workbench/services/textfile/test/textFileService.test.ts
.../workbench/services/textfile/test/textFileService.test.ts
+1
-1
src/vs/workbench/test/common/editor/untitledEditor.test.ts
src/vs/workbench/test/common/editor/untitledEditor.test.ts
+4
-4
未找到文件。
src/vs/workbench/common/editor/untitledEditorModel.ts
浏览文件 @
bb71a2ea
...
...
@@ -7,7 +7,7 @@
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
EditorModel
,
IEncodingSupport
}
from
'
vs/workbench/common/editor
'
;
import
{
StringEditorModel
}
from
'
vs/workbench/common/editor/string
EditorModel
'
;
import
{
BaseTextEditorModel
}
from
'
vs/workbench/common/editor/text
EditorModel
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
PLAINTEXT_MODE_ID
}
from
'
vs/editor/common/modes/modesRegistry
'
;
import
{
EndOfLinePreference
}
from
'
vs/editor/common/editorCommon
'
;
...
...
@@ -21,7 +21,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
import
{
IBackupFileService
,
BACKUP_FILE_RESOLVE_OPTIONS
}
from
'
vs/workbench/services/backup/common/backup
'
;
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
export
class
UntitledEditorModel
extends
String
EditorModel
implements
IEncodingSupport
{
export
class
UntitledEditorModel
extends
BaseText
EditorModel
implements
IEncodingSupport
{
public
static
DEFAULT_CONTENT_CHANGE_BUFFER_DELAY
=
CONTENT_CHANGE_EVENT_BUFFER_DELAY
;
...
...
@@ -43,8 +43,8 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
private
hasAssociatedFilePath
:
boolean
;
constructor
(
modeId
:
string
,
resource
:
URI
,
private
modeId
:
string
,
private
resource
:
URI
,
hasAssociatedFilePath
:
boolean
,
@
IModeService
modeService
:
IModeService
,
@
IModelService
modelService
:
IModelService
,
...
...
@@ -52,7 +52,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
@
ITextFileService
private
textFileService
:
ITextFileService
,
@
IConfigurationService
private
configurationService
:
IConfigurationService
)
{
super
(
''
,
modeId
,
resource
,
modeService
,
model
Service
);
super
(
modelService
,
mode
Service
);
this
.
hasAssociatedFilePath
=
hasAssociatedFilePath
;
this
.
dirty
=
false
;
...
...
@@ -167,13 +167,11 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
return
null
;
}).
then
(
backupContent
=>
{
if
(
backupContent
)
{
this
.
setValue
(
backupContent
);
}
this
.
setDirty
(
this
.
hasAssociatedFilePath
||
!!
backupContent
);
// untitled associated to file path are dirty right away as well as untitled with content
// untitled associated to file path are dirty right away as well as untitled with content
this
.
setDirty
(
this
.
hasAssociatedFilePath
||
!!
backupContent
);
return
super
.
load
(
).
then
(
model
=>
{
return
this
.
doLoad
(
backupContent
||
''
).
then
(
model
=>
{
const
configuration
=
this
.
configurationService
.
getConfiguration
<
IFilesConfiguration
>
();
// Encoding
...
...
@@ -187,6 +185,21 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
});
}
private
doLoad
(
content
:
string
):
TPromise
<
EditorModel
>
{
// Create text editor model if not yet done
if
(
!
this
.
textEditorModel
)
{
return
this
.
createTextEditorModel
(
content
,
this
.
resource
,
this
.
modeId
);
}
// Otherwise update
else
{
this
.
updateTextEditorModel
(
content
);
}
return
TPromise
.
as
<
EditorModel
>
(
this
);
}
private
onModelContentChanged
():
void
{
this
.
versionId
++
;
...
...
src/vs/workbench/services/textfile/test/textFileService.test.ts
浏览文件 @
bb71a2ea
...
...
@@ -163,7 +163,7 @@ suite('Files - TextFileService', () => {
return
untitled
.
resolve
().
then
((
model
:
UntitledEditorModel
)
=>
{
assert
.
ok
(
!
service
.
isDirty
(
untitled
.
getResource
()));
assert
.
equal
(
service
.
getDirty
().
length
,
1
);
model
.
setValue
(
'
changed
'
);
model
.
textEditorModel
.
setValue
(
'
changed
'
);
assert
.
ok
(
service
.
isDirty
(
untitled
.
getResource
()));
assert
.
equal
(
service
.
getDirty
().
length
,
2
);
...
...
src/vs/workbench/test/common/editor/untitledEditor.test.ts
浏览文件 @
bb71a2ea
...
...
@@ -162,21 +162,21 @@ suite('Workbench - Untitled Editor', () => {
});
input
.
resolve
().
then
((
model
:
UntitledEditorModel
)
=>
{
model
.
setValue
(
'
foo
'
);
model
.
textEditorModel
.
setValue
(
'
foo
'
);
assert
.
equal
(
counter
,
0
,
'
Dirty model should not trigger event immediately
'
);
TPromise
.
timeout
(
3
).
then
(()
=>
{
assert
.
equal
(
counter
,
1
,
'
Dirty model should trigger event
'
);
model
.
setValue
(
'
bar
'
);
model
.
textEditorModel
.
setValue
(
'
bar
'
);
TPromise
.
timeout
(
3
).
then
(()
=>
{
assert
.
equal
(
counter
,
2
,
'
Content change when dirty should trigger event
'
);
model
.
setValue
(
''
);
model
.
textEditorModel
.
setValue
(
''
);
TPromise
.
timeout
(
3
).
then
(()
=>
{
assert
.
equal
(
counter
,
3
,
'
Manual revert should trigger event
'
);
model
.
setValue
(
'
foo
'
);
model
.
textEditorModel
.
setValue
(
'
foo
'
);
TPromise
.
timeout
(
3
).
then
(()
=>
{
assert
.
equal
(
counter
,
4
,
'
Dirty model should trigger event
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录