Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
c01a6160
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,发现更多精彩内容 >>
提交
c01a6160
编写于
3月 23, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - allow to somewhat work with a closed editor
上级
6b4e8566
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
13 deletion
+60
-13
src/vs/workbench/api/node/extHostTextEditor.ts
src/vs/workbench/api/node/extHostTextEditor.ts
+29
-12
src/vs/workbench/test/node/api/extHostTextEditor.test.ts
src/vs/workbench/test/node/api/extHostTextEditor.test.ts
+31
-1
未找到文件。
src/vs/workbench/api/node/extHostTextEditor.ts
浏览文件 @
c01a6160
...
...
@@ -5,6 +5,7 @@
'
use strict
'
;
import
{
ok
}
from
'
vs/base/common/assert
'
;
import
{
readonly
,
illegalArgument
}
from
'
vs/base/common/errors
'
;
import
{
IdGenerator
}
from
'
vs/base/common/idGenerator
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
...
...
@@ -308,19 +309,18 @@ export class ExtHostTextEditorOptions implements vscode.TextEditorOptions {
warnOnError
(
this
.
_proxy
.
$trySetOptions
(
this
.
_id
,
bulkConfigurationUpdate
));
}
}
}
export
class
ExtHostTextEditor
implements
vscode
.
TextEditor
{
private
_proxy
:
MainThreadEditorsShape
;
private
_id
:
string
;
private
readonly
_proxy
:
MainThreadEditorsShape
;
private
readonly
_id
:
string
;
private
readonly
_documentData
:
ExtHostDocumentData
;
private
_documentData
:
ExtHostDocumentData
;
private
_selections
:
Selection
[];
private
_options
:
ExtHostTextEditorOptions
;
private
_viewColumn
:
vscode
.
ViewColumn
;
private
_disposed
:
boolean
=
false
;
constructor
(
proxy
:
MainThreadEditorsShape
,
id
:
string
,
document
:
ExtHostDocumentData
,
selections
:
Selection
[],
options
:
IResolvedTextEditorConfiguration
,
viewColumn
:
vscode
.
ViewColumn
)
{
this
.
_proxy
=
proxy
;
...
...
@@ -332,7 +332,8 @@ export class ExtHostTextEditor implements vscode.TextEditor {
}
dispose
()
{
this
.
_documentData
=
null
;
ok
(
!
this
.
_disposed
);
this
.
_disposed
=
true
;
}
@
deprecated
(
'
TextEditor.show
'
)
show
(
column
:
vscode
.
ViewColumn
)
{
...
...
@@ -346,9 +347,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
// ---- the document
get
document
():
vscode
.
TextDocument
{
return
this
.
_documentData
?
this
.
_documentData
.
document
:
undefined
;
return
this
.
_documentData
.
document
;
}
set
document
(
value
)
{
...
...
@@ -362,10 +361,13 @@ export class ExtHostTextEditor implements vscode.TextEditor {
}
set
options
(
value
:
vscode
.
TextEditorOptions
)
{
this
.
_options
.
assign
(
value
);
if
(
!
this
.
_disposed
)
{
this
.
_options
.
assign
(
value
);
}
}
_acceptOptions
(
options
:
IResolvedTextEditorConfiguration
):
void
{
ok
(
!
this
.
_disposed
);
this
.
_options
.
_accept
(
options
);
}
...
...
@@ -380,6 +382,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
}
_acceptViewColumn
(
value
:
vscode
.
ViewColumn
)
{
ok
(
!
this
.
_disposed
);
this
.
_viewColumn
=
value
;
}
...
...
@@ -437,18 +440,22 @@ export class ExtHostTextEditor implements vscode.TextEditor {
}
_acceptSelections
(
selections
:
Selection
[]):
void
{
ok
(
!
this
.
_disposed
);
this
.
_selections
=
selections
;
}
// ---- editing
edit
(
callback
:
(
edit
:
TextEditorEdit
)
=>
void
,
options
:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}
=
{
undoStopBefore
:
true
,
undoStopAfter
:
true
}):
Thenable
<
boolean
>
{
if
(
this
.
_disposed
)
{
return
TPromise
.
wrapError
<
boolean
>
(
'
TextEditor#edit not possible on closed editors
'
);
}
let
edit
=
new
TextEditorEdit
(
this
.
_documentData
.
document
,
options
);
callback
(
edit
);
return
this
.
_applyEdit
(
edit
);
}
_applyEdit
(
editBuilder
:
TextEditorEdit
):
TPromise
<
boolean
>
{
private
_applyEdit
(
editBuilder
:
TextEditorEdit
):
TPromise
<
boolean
>
{
let
editData
=
editBuilder
.
finalize
();
// prepare data for serialization
...
...
@@ -468,7 +475,9 @@ export class ExtHostTextEditor implements vscode.TextEditor {
}
insertSnippet
(
snippet
:
SnippetString
,
where
?:
Position
|
Position
[]
|
Range
|
Range
[],
options
:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}
=
{
undoStopBefore
:
true
,
undoStopAfter
:
true
}):
Thenable
<
boolean
>
{
if
(
this
.
_disposed
)
{
return
TPromise
.
wrapError
<
boolean
>
(
'
TextEditor#insertSnippet not possible on closed editors
'
);
}
let
ranges
:
IRange
[];
if
(
!
where
||
(
Array
.
isArray
(
where
)
&&
where
.
length
===
0
))
{
...
...
@@ -498,6 +507,14 @@ export class ExtHostTextEditor implements vscode.TextEditor {
// ---- util
private
_runOnProxy
(
callback
:
()
=>
TPromise
<
any
>
,
silent
:
boolean
):
TPromise
<
ExtHostTextEditor
>
{
if
(
this
.
_disposed
)
{
if
(
!
silent
)
{
return
TPromise
.
wrapError
(
silent
);
}
else
{
console
.
warn
(
'
TextEditor is closed/disposed
'
);
return
TPromise
.
as
(
undefined
);
}
}
return
callback
().
then
(()
=>
this
,
err
=>
{
if
(
!
silent
)
{
return
TPromise
.
wrapError
(
silent
);
...
...
src/vs/workbench/test/node/api/extHostTextEditor.test.ts
浏览文件 @
c01a6160
...
...
@@ -10,7 +10,37 @@ import { TextEditorLineNumbersStyle } from 'vs/workbench/api/node/extHostTypes';
import
{
TextEditorCursorStyle
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IResolvedTextEditorConfiguration
,
ITextEditorConfigurationUpdate
}
from
'
vs/workbench/api/node/mainThreadEditor
'
;
import
{
MainThreadEditorsShape
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
ExtHostTextEditorOptions
}
from
'
vs/workbench/api/node/extHostTextEditor
'
;
import
{
ExtHostTextEditorOptions
,
ExtHostTextEditor
}
from
'
vs/workbench/api/node/extHostTextEditor
'
;
import
{
ExtHostDocumentData
}
from
'
vs/workbench/api/node/extHostDocumentData
'
;
import
URI
from
'
vs/base/common/uri
'
;
suite
(
'
ExtHostTextEditor
'
,
()
=>
{
let
editor
:
ExtHostTextEditor
;
setup
(()
=>
{
let
doc
=
new
ExtHostDocumentData
(
undefined
,
URI
.
file
(
''
),
[
'
aaaa bbbb+cccc abc
'
],
'
\n
'
,
'
text
'
,
1
,
false
);
editor
=
new
ExtHostTextEditor
(
null
,
'
fake
'
,
doc
,
[],
{
cursorStyle
:
0
,
insertSpaces
:
true
,
lineNumbers
:
1
,
tabSize
:
4
},
1
);
});
test
(
'
disposed editor
'
,
()
=>
{
assert
.
ok
(
editor
.
document
);
editor
.
_acceptViewColumn
(
3
);
assert
.
equal
(
3
,
editor
.
viewColumn
);
editor
.
dispose
();
assert
.
throws
(()
=>
editor
.
_acceptViewColumn
(
2
));
assert
.
equal
(
3
,
editor
.
viewColumn
);
assert
.
ok
(
editor
.
document
);
assert
.
throws
(()
=>
editor
.
_acceptOptions
(
null
));
assert
.
throws
(()
=>
editor
.
_acceptSelections
([]));
});
});
suite
(
'
ExtHostTextEditorOptions
'
,
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录