Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d46681e2
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,发现更多精彩内容 >>
提交
d46681e2
编写于
8月 22, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tests
上级
e055454a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
256 addition
and
7 deletion
+256
-7
src/vs/editor/contrib/snippet/common/snippetController.ts
src/vs/editor/contrib/snippet/common/snippetController.ts
+8
-6
src/vs/editor/contrib/snippet/test/common/snippetController.test.ts
...tor/contrib/snippet/test/common/snippetController.test.ts
+222
-0
src/vs/editor/test/common/core/range.test.ts
src/vs/editor/test/common/core/range.test.ts
+25
-0
src/vs/workbench/parts/emmet/node/editorAccessor.ts
src/vs/workbench/parts/emmet/node/editorAccessor.ts
+1
-1
未找到文件。
src/vs/editor/contrib/snippet/common/snippetController.ts
浏览文件 @
d46681e2
...
...
@@ -19,7 +19,7 @@ import {ICodeSnippet, CodeSnippet} from './snippet';
import
EditorContextKeys
=
editorCommon
.
EditorContextKeys
;
class
InsertSnippetController
{
export
class
InsertSnippetController
{
private
editor
:
editorCommon
.
ICommonCodeEditor
;
private
model
:
editorCommon
.
IModel
;
...
...
@@ -313,10 +313,10 @@ class InsertSnippetController {
if
(
this
.
isFinished
)
{
return
;
}
this
.
_onStop
();
this
.
isFinished
=
true
;
this
.
_onStop
();
this
.
listenersToRemove
=
dispose
(
this
.
listenersToRemove
);
for
(
var
i
=
0
;
i
<
this
.
trackedPlaceHolders
.
length
;
i
++
)
{
...
...
@@ -358,7 +358,7 @@ export class SnippetController {
}
private
_editor
:
editorCommon
.
ICommonCodeEditor
;
pr
ivate
_currentController
:
InsertSnippetController
;
pr
otected
_currentController
:
InsertSnippetController
;
private
_inSnippetMode
:
IContextKey
<
boolean
>
;
constructor
(
editor
:
editorCommon
.
ICommonCodeEditor
,
@
IContextKeyService
contextKeyService
:
IContextKeyService
)
{
...
...
@@ -393,12 +393,12 @@ export class SnippetController {
/**
* Inserts once `snippet` at the start of `replaceRange`, after deleting `replaceRange`.
*/
public
runWithReplaceRange
(
snippet
:
CodeSnippet
,
replaceRange
:
Range
,
undoStops
:
boolean
):
void
{
public
runWithReplaceRange
(
snippet
:
CodeSnippet
,
replaceRange
:
Range
):
void
{
this
.
_runAndRestoreController
(()
=>
{
this
.
_runPreparedSnippetForPrimarySelection
({
typeRange
:
replaceRange
,
adaptedSnippet
:
SnippetController
.
_getAdaptedSnippet
(
this
.
_editor
.
getModel
(),
snippet
,
replaceRange
)
},
undoStops
);
},
false
);
});
}
...
...
@@ -470,6 +470,8 @@ export class SnippetController {
this
.
_inSnippetMode
.
set
(
true
);
this
.
_currentController
=
new
InsertSnippetController
(
this
.
_editor
,
prepared
.
adaptedSnippet
,
prepared
.
typeRange
.
startLineNumber
,
initialAlternativeVersionId
,
()
=>
{
this
.
_inSnippetMode
.
reset
();
this
.
_currentController
.
dispose
();
this
.
_currentController
=
null
;
});
}
}
...
...
src/vs/editor/contrib/snippet/test/common/snippetController.test.ts
0 → 100644
浏览文件 @
d46681e2
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
CodeSnippet
}
from
'
vs/editor/contrib/snippet/common/snippet
'
;
import
{
SnippetController
}
from
'
vs/editor/contrib/snippet/common/snippetController
'
;
import
{
MockCodeEditor
,
withMockCodeEditor
}
from
'
vs/editor/test/common/mocks/mockCodeEditor
'
;
import
{
Cursor
}
from
'
vs/editor/common/controller/cursor
'
;
class
TestSnippetController
extends
SnippetController
{
isInSnippetMode
():
boolean
{
return
!!
this
.
_currentController
;
}
}
suite
(
'
SnippetController
'
,
()
=>
{
function
snippetTest
(
cb
:(
editor
:
MockCodeEditor
,
cursor
:
Cursor
,
codeSnippet
:
CodeSnippet
,
snippetController
:
TestSnippetController
)
=>
void
):
void
{
withMockCodeEditor
([
'
function test() {
'
,
'
\t
var x = 3;
'
,
'
\t
var arr = [];
'
,
'
\t
'
,
'
}
'
],
{},
(
editor
,
cursor
)
=>
{
editor
.
getModel
().
updateOptions
({
insertSpaces
:
false
});
let
snippetController
=
editor
.
registerAndInstantiateContribution
<
TestSnippetController
>
(
TestSnippetController
);
let
codeSnippet
=
new
CodeSnippet
([
'
for (var {{index}}; {{index}} < {{array}}.length; {{index}}++) {
'
,
'
\t
var element = {{array}}[{{index}}];
'
,
'
\t
{{}}
'
,
'
}
'
].
join
(
'
\n
'
));
cb
(
editor
,
cursor
,
codeSnippet
,
snippetController
);
snippetController
.
dispose
();
});
}
test
(
'
Simple accepted
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
4
),
'
\t
for (var index; index < array.length; index++) {
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
5
),
'
\t\t
var element = array[index];
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
6
),
'
\t\t
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
7
),
'
\t
}
'
);
editor
.
trigger
(
'
test
'
,
'
type
'
,
{
text
:
'
i
'
});
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
4
),
'
\t
for (var i; i < array.length; i++) {
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
5
),
'
\t\t
var element = array[i];
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
6
),
'
\t\t
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
7
),
'
\t
}
'
);
snippetController
.
jumpToNextPlaceholder
();
editor
.
trigger
(
'
test
'
,
'
type
'
,
{
text
:
'
arr
'
});
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
4
),
'
\t
for (var i; i < arr.length; i++) {
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
5
),
'
\t\t
var element = arr[i];
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
6
),
'
\t\t
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
7
),
'
\t
}
'
);
snippetController
.
jumpToPrevPlaceholder
();
editor
.
trigger
(
'
test
'
,
'
type
'
,
{
text
:
'
j
'
});
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
4
),
'
\t
for (var j; j < arr.length; j++) {
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
5
),
'
\t\t
var element = arr[j];
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
6
),
'
\t\t
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
7
),
'
\t
}
'
);
snippetController
.
acceptSnippet
();
assert
.
deepEqual
(
editor
.
getPosition
(),
new
Position
(
6
,
3
));
});
});
test
(
'
Simple canceled
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
4
),
'
\t
for (var index; index < array.length; index++) {
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
5
),
'
\t\t
var element = array[index];
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
6
),
'
\t\t
'
);
assert
.
equal
(
editor
.
getModel
().
getLineContent
(
7
),
'
\t
}
'
);
snippetController
.
leaveSnippet
();
assert
.
deepEqual
(
editor
.
getPosition
(),
new
Position
(
4
,
16
));
});
});
test
(
'
Stops when deleting lines above
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
editor
.
getModel
().
applyEdits
([{
forceMoveMarkers
:
false
,
identifier
:
null
,
isAutoWhitespaceEdit
:
false
,
range
:
new
Range
(
1
,
1
,
3
,
1
),
text
:
null
}]);
assert
.
equal
(
snippetController
.
isInSnippetMode
(),
false
);
});
});
test
(
'
Stops when deleting lines below
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
editor
.
getModel
().
applyEdits
([{
forceMoveMarkers
:
false
,
identifier
:
null
,
isAutoWhitespaceEdit
:
false
,
range
:
new
Range
(
7
,
100
,
8
,
100
),
text
:
null
}]);
assert
.
equal
(
snippetController
.
isInSnippetMode
(),
false
);
});
});
test
(
'
Stops when inserting lines above
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
editor
.
getModel
().
applyEdits
([{
forceMoveMarkers
:
false
,
identifier
:
null
,
isAutoWhitespaceEdit
:
false
,
range
:
new
Range
(
1
,
100
,
1
,
100
),
text
:
'
\n
Hello
'
}]);
assert
.
equal
(
snippetController
.
isInSnippetMode
(),
false
);
});
});
test
(
'
Stops when inserting lines below
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
editor
.
getModel
().
applyEdits
([{
forceMoveMarkers
:
false
,
identifier
:
null
,
isAutoWhitespaceEdit
:
false
,
range
:
new
Range
(
8
,
100
,
8
,
100
),
text
:
'
\n
Hello
'
}]);
assert
.
equal
(
snippetController
.
isInSnippetMode
(),
false
);
});
});
test
(
'
Stops when calling model.setValue()
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
editor
.
getModel
().
setValue
(
'
goodbye
'
);
assert
.
equal
(
snippetController
.
isInSnippetMode
(),
false
);
});
});
test
(
'
Stops when undoing
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
editor
.
getModel
().
undo
();
assert
.
equal
(
snippetController
.
isInSnippetMode
(),
false
);
});
});
test
(
'
Stops when moving cursor outside
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
editor
.
setPosition
({
lineNumber
:
1
,
column
:
1
});
assert
.
equal
(
snippetController
.
isInSnippetMode
(),
false
);
});
});
test
(
'
Stops when disconnecting editor model
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
editor
.
setModel
(
null
);
assert
.
equal
(
snippetController
.
isInSnippetMode
(),
false
);
});
});
test
(
'
Stops when disposing editor
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
run
(
codeSnippet
,
0
,
0
,
false
);
snippetController
.
dispose
();
assert
.
equal
(
snippetController
.
isInSnippetMode
(),
false
);
});
});
});
\ No newline at end of file
src/vs/editor/test/common/core/range.test.ts
浏览文件 @
d46681e2
...
...
@@ -6,6 +6,7 @@
import
*
as
assert
from
'
assert
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
suite
(
'
Editor Core - Range
'
,
()
=>
{
test
(
'
empty range
'
,
()
=>
{
...
...
@@ -92,4 +93,28 @@ suite('Editor Core - Range', () => {
b
=
new
Range
(
1
,
1
,
1
,
4
);
assert
.
ok
(
Range
.
compareRangesUsingEnds
(
a
,
b
)
>
0
,
'
a.start = b.start, a.end > b.end
'
);
});
test
(
'
containsPosition
'
,
()
=>
{
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsPosition
(
new
Position
(
1
,
3
)),
false
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsPosition
(
new
Position
(
2
,
1
)),
false
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsPosition
(
new
Position
(
2
,
2
)),
true
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsPosition
(
new
Position
(
2
,
3
)),
true
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsPosition
(
new
Position
(
3
,
1
)),
true
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsPosition
(
new
Position
(
5
,
9
)),
true
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsPosition
(
new
Position
(
5
,
10
)),
true
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsPosition
(
new
Position
(
5
,
11
)),
false
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsPosition
(
new
Position
(
6
,
1
)),
false
);
});
test
(
'
containsRange
'
,
()
=>
{
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsRange
(
new
Range
(
1
,
3
,
2
,
2
)),
false
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsRange
(
new
Range
(
2
,
1
,
2
,
2
)),
false
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsRange
(
new
Range
(
2
,
2
,
5
,
11
)),
false
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsRange
(
new
Range
(
2
,
2
,
6
,
1
)),
false
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsRange
(
new
Range
(
5
,
9
,
6
,
1
)),
false
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsRange
(
new
Range
(
5
,
10
,
6
,
1
)),
false
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsRange
(
new
Range
(
2
,
2
,
5
,
10
)),
true
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsRange
(
new
Range
(
2
,
3
,
5
,
9
)),
true
);
assert
.
equal
(
new
Range
(
2
,
2
,
5
,
10
).
containsRange
(
new
Range
(
3
,
100
,
4
,
100
)),
true
);
});
});
src/vs/workbench/parts/emmet/node/editorAccessor.ts
浏览文件 @
d46681e2
...
...
@@ -89,7 +89,7 @@ export class EditorAccessor implements emmet.Editor {
let
range
=
new
Range
(
startPosition
.
lineNumber
,
startPosition
.
column
,
endPosition
.
lineNumber
,
endPosition
.
column
);
let
snippet
=
snippets
.
CodeSnippet
.
convertExternalSnippet
(
value
,
snippets
.
ExternalSnippetType
.
EmmetSnippet
);
let
codeSnippet
=
new
snippets
.
CodeSnippet
(
snippet
);
SnippetController
.
get
(
this
.
editor
).
runWithReplaceRange
(
codeSnippet
,
range
,
false
);
SnippetController
.
get
(
this
.
editor
).
runWithReplaceRange
(
codeSnippet
,
range
);
}
public
onAfterEmmetAction
():
void
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录