Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
bc053829
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,发现更多精彩内容 >>
提交
bc053829
编写于
5月 11, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wire up most of the old snippet controller tests
上级
f4023b38
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
637 addition
and
15 deletion
+637
-15
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
+40
-12
src/vs/editor/contrib/snippet/browser/snippetController2.ts
src/vs/editor/contrib/snippet/browser/snippetController2.ts
+6
-1
src/vs/editor/contrib/snippet/test/browser/editorSnippets.test.ts
...ditor/contrib/snippet/test/browser/editorSnippets.test.ts
+3
-2
src/vs/editor/contrib/snippet/test/browser/snippetController2.old.test.ts
...ntrib/snippet/test/browser/snippetController2.old.test.ts
+588
-0
未找到文件。
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
浏览文件 @
bc053829
...
...
@@ -164,11 +164,9 @@ export class SnippetSession {
const
lineLeadingWhitespace
=
getLeadingWhitespace
(
line
,
0
,
position
.
column
-
1
);
const
templateLines
=
template
.
split
(
/
\r\n
|
\r
|
\n
/
);
for
(
let
i
=
0
;
i
<
templateLines
.
length
;
i
++
)
{
for
(
let
i
=
1
;
i
<
templateLines
.
length
;
i
++
)
{
let
templateLeadingWhitespace
=
getLeadingWhitespace
(
templateLines
[
i
]);
if
(
templateLeadingWhitespace
.
length
>
0
)
{
templateLines
[
i
]
=
model
.
normalizeIndentation
(
lineLeadingWhitespace
+
templateLeadingWhitespace
)
+
templateLines
[
i
].
substr
(
templateLeadingWhitespace
.
length
);
}
templateLines
[
i
]
=
model
.
normalizeIndentation
(
lineLeadingWhitespace
+
templateLeadingWhitespace
)
+
templateLines
[
i
].
substr
(
templateLeadingWhitespace
.
length
);
}
return
templateLines
.
join
(
model
.
getEOL
());
}
...
...
@@ -219,6 +217,12 @@ export class SnippetSession {
let
edits
:
IIdentifiedSingleEditOperation
[]
=
[];
let
model
=
this
.
_editor
.
getModel
();
// know what text the overwrite[Before|After] extensions
// of the primary curser have selected because only when
// secondary selections extend to the same text we can grow them
let
firstBeforeText
=
model
.
getValueInRange
(
SnippetSession
.
adjustSelection
(
model
,
this
.
_editor
.
getSelection
(),
this
.
_overwriteBefore
,
0
));
let
firstAfterText
=
model
.
getValueInRange
(
SnippetSession
.
adjustSelection
(
model
,
this
.
_editor
.
getSelection
(),
0
,
this
.
_overwriteAfter
));
// sort selections by their start position but remeber
// the original index. that allows you to create correct
// offset-based selection logic without changing the
...
...
@@ -228,17 +232,37 @@ export class SnippetSession {
.
sort
((
a
,
b
)
=>
Range
.
compareRangesUsingStarts
(
a
.
selection
,
b
.
selection
));
for
(
const
{
selection
,
idx
}
of
indexedSelection
)
{
const
range
=
SnippetSession
.
adjustSelection
(
model
,
selection
,
this
.
_overwriteBefore
,
this
.
_overwriteAfter
);
const
start
=
range
.
getStartPosition
();
// extend selection with the `overwriteBefore` and `overwriteAfter` and then
// compare if this matches the extensions of the primary selection
let
extensionBefore
=
SnippetSession
.
adjustSelection
(
model
,
selection
,
this
.
_overwriteBefore
,
0
);
let
extensionAfter
=
SnippetSession
.
adjustSelection
(
model
,
selection
,
0
,
this
.
_overwriteAfter
);
if
(
firstBeforeText
!==
model
.
getValueInRange
(
extensionBefore
))
{
extensionBefore
=
selection
;
}
if
(
firstAfterText
!==
model
.
getValueInRange
(
extensionAfter
))
{
extensionAfter
=
selection
;
}
// merge the before and after selection into one
const
snippetSelection
=
selection
.
setStartPosition
(
extensionBefore
.
startLineNumber
,
extensionBefore
.
startColumn
)
.
setEndPosition
(
extensionAfter
.
endLineNumber
,
extensionAfter
.
endColumn
);
// adjust the template string to match the indentation and
// whitespace rules of this insert location (can be different for each cursor)
const
start
=
snippetSelection
.
getStartPosition
();
const
adjustedTemplate
=
SnippetSession
.
normalizeWhitespace
(
model
,
start
,
this
.
_template
);
const
snippet
=
SnippetParser
.
parse
(
adjustedTemplate
).
resolveVariables
(
new
EditorSnippetVariableResolver
(
model
,
range
));
const
snippet
=
SnippetParser
.
parse
(
adjustedTemplate
).
resolveVariables
(
new
EditorSnippetVariableResolver
(
model
,
snippetSelection
));
const
offset
=
model
.
getOffsetAt
(
start
)
+
delta
;
delta
+=
snippet
.
text
.
length
-
model
.
getValueLengthInRange
(
snippetSelection
);
edits
[
idx
]
=
EditOperation
.
replaceMove
(
range
,
snippet
.
text
);
// store snippets with the index of their originating selection.
// that ensures the primiary cursor stays primary despite not being
// the one with lowest start position
edits
[
idx
]
=
EditOperation
.
replaceMove
(
snippetSelection
,
snippet
.
text
);
this
.
_snippets
[
idx
]
=
new
OneSnippet
(
this
.
_editor
,
snippet
,
offset
);
delta
+=
snippet
.
text
.
length
-
model
.
getValueLengthInRange
(
range
);
}
// make insert edit and start with first selections
...
...
@@ -291,8 +315,12 @@ export class SnippetSession {
for
(
const
selection
of
selections
)
{
let
found
=
false
;
for
(
const
snippet
of
this
.
_snippets
)
{
if
(
snippet
.
range
.
containsRange
(
selection
))
{
for
(
const
{
range
}
of
this
.
_snippets
)
{
if
(
!
range
)
{
// all deleted
return
false
;
}
if
(
range
.
containsRange
(
selection
))
{
found
=
true
;
break
;
}
...
...
src/vs/editor/contrib/snippet/browser/snippetController2.ts
浏览文件 @
bc053829
...
...
@@ -43,6 +43,8 @@ export class SnippetController2 {
dispose
():
void
{
this
.
_inSnippet
.
reset
();
this
.
_hasPrevTabstop
.
reset
();
this
.
_hasNextTabstop
.
reset
();
dispose
(
this
.
_snippet
);
}
...
...
@@ -55,7 +57,10 @@ export class SnippetController2 {
this
.
cancel
();
}
this
.
_snippet
=
new
SnippetSession
(
this
.
_editor
,
template
,
overwriteBefore
,
overwriteAfter
);
this
.
_snippetListener
=
[
this
.
_editor
.
onDidChangeCursorSelection
(()
=>
this
.
_updateState
())];
this
.
_snippetListener
=
[
this
.
_editor
.
onDidChangeModel
(()
=>
this
.
cancel
()),
this
.
_editor
.
onDidChangeCursorSelection
(()
=>
this
.
_updateState
())
];
this
.
_snippet
.
insert
();
}
...
...
src/vs/editor/contrib/snippet/test/browser/editorSnippets.test.ts
浏览文件 @
bc053829
...
...
@@ -50,6 +50,7 @@ suite('SnippetSession', function () {
assertNormalized
(
new
Position
(
1
,
1
),
'
foo
\r
bar
'
,
'
foo
\n
bar
'
);
assertNormalized
(
new
Position
(
2
,
5
),
'
foo
\r\t
bar
'
,
'
foo
\n
bar
'
);
assertNormalized
(
new
Position
(
2
,
3
),
'
foo
\r\t
bar
'
,
'
foo
\n
bar
'
);
assertNormalized
(
new
Position
(
2
,
5
),
'
foo
\r\t
bar
\n
foo
'
,
'
foo
\n
bar
\n
foo
'
);
});
test
(
'
adjust selection (overwrite[Before|After])
'
,
function
()
{
...
...
@@ -111,12 +112,12 @@ suite('SnippetSession', function () {
const
session
=
new
SnippetSession
(
editor
,
'
foo
\n\t
${1:bar}
\n
$0
'
);
session
.
insert
();
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
foo
\n
bar
\n
function foo() {
\n
foo
\n
bar
\n
console.log(a);
\n
}
'
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
foo
\n
bar
\n
function foo() {
\n
foo
\n
bar
\n
console.log(a);
\n
}
'
);
assertSelections
(
editor
,
new
Selection
(
2
,
5
,
2
,
8
),
new
Selection
(
5
,
9
,
5
,
12
));
session
.
next
();
assertSelections
(
editor
,
new
Selection
(
3
,
1
,
3
,
1
),
new
Selection
(
6
,
1
,
6
,
1
));
assertSelections
(
editor
,
new
Selection
(
3
,
1
,
3
,
1
),
new
Selection
(
6
,
5
,
6
,
5
));
});
test
(
'
snippets, selections -> next/prev
'
,
()
=>
{
...
...
src/vs/editor/contrib/snippet/test/browser/snippetController2.old.test.ts
0 → 100644
浏览文件 @
bc053829
/*---------------------------------------------------------------------------------------------
* 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
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
SnippetController2
}
from
'
vs/editor/contrib/snippet/browser/snippetController2
'
;
import
{
MockCodeEditor
,
withMockCodeEditor
}
from
'
vs/editor/test/common/mocks/mockCodeEditor
'
;
import
{
Cursor
}
from
'
vs/editor/common/controller/cursor
'
;
import
{
IContextKeyService
}
from
"
vs/platform/contextkey/common/contextkey
"
;
import
{
ICommonCodeEditor
}
from
"
vs/editor/common/editorCommon
"
;
class
TestSnippetController
extends
SnippetController2
{
constructor
(
editor
:
ICommonCodeEditor
,
@
IContextKeyService
private
_contextKeyService
:
IContextKeyService
)
{
super
(
editor
,
_contextKeyService
);
}
isInSnippetMode
():
boolean
{
return
SnippetController2
.
InSnippetMode
.
getValue
(
this
.
_contextKeyService
);
}
}
suite
(
'
SnippetController
'
,
()
=>
{
function
snippetTest
(
cb
:
(
editor
:
MockCodeEditor
,
cursor
:
Cursor
,
template
:
string
,
snippetController
:
TestSnippetController
)
=>
void
,
lines
?:
string
[]):
void
{
if
(
!
lines
)
{
lines
=
[
'
function test() {
'
,
'
\t
var x = 3;
'
,
'
\t
var arr = [];
'
,
'
\t
'
,
'
}
'
];
};
withMockCodeEditor
(
lines
,
{},
(
editor
,
cursor
)
=>
{
editor
.
getModel
().
updateOptions
({
insertSpaces
:
false
});
let
snippetController
=
editor
.
registerAndInstantiateContribution
<
TestSnippetController
>
(
TestSnippetController
);
let
template
=
[
'
for (var ${1:index}; $1 < ${2:array}.length; $1++) {
'
,
'
\t
var element = $2[$1];
'
,
'
\t
$0
'
,
'
}
'
].
join
(
'
\n
'
);
cb
(
editor
,
cursor
,
template
,
snippetController
);
snippetController
.
dispose
();
});
}
test
(
'
Simple accepted
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
template
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
insert
(
template
,
0
,
0
);
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
.
next
();
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
.
prev
();
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
.
next
();
snippetController
.
next
();
assert
.
deepEqual
(
editor
.
getPosition
(),
new
Position
(
6
,
3
));
});
});
test
(
'
Simple canceled
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
template
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
insert
(
template
,
0
,
0
);
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
.
cancel
();
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.insert(codeSnippet, 0, 0);
// 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);
// editor.getModel().applyEdits([{
// forceMoveMarkers: false,
// identifier: null,
// isAutoWhitespaceEdit: false,
// range: new Range(8, 1, 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);
// editor.getModel().applyEdits([{
// forceMoveMarkers: false,
// identifier: null,
// isAutoWhitespaceEdit: false,
// range: new Range(1, 100, 1, 100),
// text: '\nHello'
// }]);
// 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);
// editor.getModel().applyEdits([{
// forceMoveMarkers: false,
// identifier: null,
// isAutoWhitespaceEdit: false,
// range: new Range(8, 100, 8, 100),
// text: '\nHello'
// }]);
// assert.equal(snippetController.isInSnippetMode(), false);
// });
// });
test
(
'
Stops when calling model.setValue()
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setPosition
({
lineNumber
:
4
,
column
:
2
});
snippetController
.
insert
(
codeSnippet
,
0
,
0
);
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);
// 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
.
insert
(
codeSnippet
,
0
,
0
);
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
.
insert
(
codeSnippet
,
0
,
0
);
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
.
insert
(
codeSnippet
,
0
,
0
);
snippetController
.
dispose
();
assert
.
equal
(
snippetController
.
isInSnippetMode
(),
false
);
});
});
test
(
'
Final tabstop with multiple selections
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
1
,
1
,
1
),
new
Selection
(
2
,
1
,
2
,
1
),
]);
codeSnippet
=
'
foo$0
'
;
snippetController
.
insert
(
codeSnippet
,
0
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
2
);
const
[
first
,
second
]
=
editor
.
getSelections
();
assert
.
ok
(
first
.
equalsRange
({
startLineNumber
:
1
,
startColumn
:
4
,
endLineNumber
:
1
,
endColumn
:
4
}),
first
.
toString
());
assert
.
ok
(
second
.
equalsRange
({
startLineNumber
:
2
,
startColumn
:
4
,
endLineNumber
:
2
,
endColumn
:
4
}),
second
.
toString
());
});
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
1
,
1
,
1
),
new
Selection
(
2
,
1
,
2
,
1
),
]);
codeSnippet
=
'
foo$0bar
'
;
snippetController
.
insert
(
codeSnippet
,
0
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
2
);
const
[
first
,
second
]
=
editor
.
getSelections
();
assert
.
ok
(
first
.
equalsRange
({
startLineNumber
:
1
,
startColumn
:
4
,
endLineNumber
:
1
,
endColumn
:
4
}),
first
.
toString
());
assert
.
ok
(
second
.
equalsRange
({
startLineNumber
:
2
,
startColumn
:
4
,
endLineNumber
:
2
,
endColumn
:
4
}),
second
.
toString
());
});
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
1
,
1
,
1
),
new
Selection
(
1
,
5
,
1
,
5
),
]);
codeSnippet
=
'
foo$0bar
'
;
snippetController
.
insert
(
codeSnippet
,
0
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
2
);
const
[
first
,
second
]
=
editor
.
getSelections
();
assert
.
ok
(
first
.
equalsRange
({
startLineNumber
:
1
,
startColumn
:
4
,
endLineNumber
:
1
,
endColumn
:
4
}),
first
.
toString
());
assert
.
ok
(
second
.
equalsRange
({
startLineNumber
:
1
,
startColumn
:
14
,
endLineNumber
:
1
,
endColumn
:
14
}),
second
.
toString
());
});
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
1
,
1
,
1
),
new
Selection
(
1
,
5
,
1
,
5
),
]);
codeSnippet
=
'
foo
\n
$0
\n
bar
'
;
snippetController
.
insert
(
codeSnippet
,
0
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
2
);
const
[
first
,
second
]
=
editor
.
getSelections
();
assert
.
ok
(
first
.
equalsRange
({
startLineNumber
:
2
,
startColumn
:
1
,
endLineNumber
:
2
,
endColumn
:
1
}),
first
.
toString
());
assert
.
ok
(
second
.
equalsRange
({
startLineNumber
:
4
,
startColumn
:
1
,
endLineNumber
:
4
,
endColumn
:
1
}),
second
.
toString
());
});
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
1
,
1
,
1
),
new
Selection
(
1
,
5
,
1
,
5
),
]);
codeSnippet
=
'
foo
\n
$0
\n
bar
'
;
snippetController
.
insert
(
codeSnippet
,
0
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
2
);
const
[
first
,
second
]
=
editor
.
getSelections
();
assert
.
ok
(
first
.
equalsRange
({
startLineNumber
:
2
,
startColumn
:
1
,
endLineNumber
:
2
,
endColumn
:
1
}),
first
.
toString
());
assert
.
ok
(
second
.
equalsRange
({
startLineNumber
:
4
,
startColumn
:
1
,
endLineNumber
:
4
,
endColumn
:
1
}),
second
.
toString
());
});
snippetTest
((
editor
,
cursor
,
codeSnippet
,
snippetController
)
=>
{
editor
.
setSelections
([
new
Selection
(
2
,
7
,
2
,
7
),
]);
codeSnippet
=
'
xo$0r
'
;
snippetController
.
insert
(
codeSnippet
,
1
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
1
);
assert
.
ok
(
editor
.
getSelection
().
equalsRange
({
startLineNumber
:
2
,
startColumn
:
8
,
endColumn
:
8
,
endLineNumber
:
2
}));
});
});
test
(
'
Final tabstop, #11742 simple
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelection
(
new
Selection
(
1
,
19
,
1
,
19
));
codeSnippet
=
'
{{% url_**$1** %}}
'
;
controller
.
insert
(
codeSnippet
,
2
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
1
);
assert
.
ok
(
editor
.
getSelection
().
equalsRange
({
startLineNumber
:
1
,
startColumn
:
27
,
endLineNumber
:
1
,
endColumn
:
27
}));
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
example example {{% url_**** %}}
'
);
},
[
'
example example sc
'
]);
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelection
(
new
Selection
(
1
,
3
,
1
,
3
));
codeSnippet
=
[
'
afterEach((done) => {
'
,
'
\t
${1}test
'
,
'
});
'
].
join
(
'
\n
'
);
controller
.
insert
(
codeSnippet
,
2
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
1
);
assert
.
ok
(
editor
.
getSelection
().
equalsRange
({
startLineNumber
:
2
,
startColumn
:
2
,
endLineNumber
:
2
,
endColumn
:
2
}),
editor
.
getSelection
().
toString
());
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
afterEach((done) => {
\n\t
test
\n
});
'
);
},
[
'
af
'
]);
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelection
(
new
Selection
(
1
,
3
,
1
,
3
));
codeSnippet
=
[
'
afterEach((done) => {
'
,
'
${1}
\t
test
'
,
'
});
'
].
join
(
'
\n
'
);
controller
.
insert
(
codeSnippet
,
2
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
1
);
assert
.
ok
(
editor
.
getSelection
().
equalsRange
({
startLineNumber
:
2
,
startColumn
:
1
,
endLineNumber
:
2
,
endColumn
:
1
}),
editor
.
getSelection
().
toString
());
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
afterEach((done) => {
\n\t
test
\n
});
'
);
},
[
'
af
'
]);
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelection
(
new
Selection
(
1
,
9
,
1
,
9
));
codeSnippet
=
[
'
aft${1}er
'
].
join
(
'
\n
'
);
controller
.
insert
(
codeSnippet
,
8
,
0
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
after
'
);
assert
.
equal
(
editor
.
getSelections
().
length
,
1
);
assert
.
ok
(
editor
.
getSelection
().
equalsRange
({
startLineNumber
:
1
,
startColumn
:
4
,
endLineNumber
:
1
,
endColumn
:
4
}),
editor
.
getSelection
().
toString
());
},
[
'
afterone
'
]);
});
test
(
'
Final tabstop, #11742 different indents
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
2
,
4
,
2
,
4
),
new
Selection
(
1
,
3
,
1
,
3
)
]);
codeSnippet
=
[
'
afterEach((done) => {
'
,
'
\t
${0}test
'
,
'
});
'
].
join
(
'
\n
'
);
controller
.
insert
(
codeSnippet
,
2
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
2
);
const
[
first
,
second
]
=
editor
.
getSelections
();
assert
.
ok
(
first
.
equalsRange
({
startLineNumber
:
5
,
startColumn
:
3
,
endLineNumber
:
5
,
endColumn
:
3
}),
first
.
toString
());
assert
.
ok
(
second
.
equalsRange
({
startLineNumber
:
2
,
startColumn
:
2
,
endLineNumber
:
2
,
endColumn
:
2
}),
second
.
toString
());
},
[
'
af
'
,
'
\t
af
'
]);
});
test
(
'
Final tabstop, #11890 stay at the beginning
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
5
,
1
,
5
)
]);
codeSnippet
=
[
'
afterEach((done) => {
'
,
'
${1}
\t
test
'
,
'
});
'
].
join
(
'
\n
'
);
controller
.
insert
(
codeSnippet
,
2
,
0
);
assert
.
equal
(
editor
.
getSelections
().
length
,
1
);
const
[
first
]
=
editor
.
getSelections
();
assert
.
ok
(
first
.
equalsRange
({
startLineNumber
:
2
,
startColumn
:
3
,
endLineNumber
:
2
,
endColumn
:
3
}),
first
.
toString
());
},
[
'
af
'
]);
});
test
(
'
Final tabstop, no tabstop
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
3
,
1
,
3
)
]);
codeSnippet
=
'
afterEach
'
;
controller
.
insert
(
codeSnippet
,
2
,
0
);
assert
.
ok
(
editor
.
getSelection
().
equalsRange
({
startLineNumber
:
1
,
startColumn
:
10
,
endLineNumber
:
1
,
endColumn
:
10
}));
},
[
'
af
'
,
'
\t
af
'
]);
});
test
(
'
Multiple cursor and overwriteBefore/After, issue #11060
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
7
,
1
,
7
),
new
Selection
(
2
,
4
,
2
,
4
)
]);
codeSnippet
=
'
_foo
'
;
controller
.
insert
(
codeSnippet
,
1
,
0
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
this._foo
\n
abc_foo
'
);
},
[
'
this._
'
,
'
abc
'
]);
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
7
,
1
,
7
),
new
Selection
(
2
,
4
,
2
,
4
)
]);
codeSnippet
=
'
XX
'
;
controller
.
insert
(
codeSnippet
,
1
,
0
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
this.XX
\n
abcXX
'
);
},
[
'
this._
'
,
'
abc
'
]);
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
7
,
1
,
7
),
new
Selection
(
2
,
4
,
2
,
4
),
new
Selection
(
3
,
5
,
3
,
5
)
]);
codeSnippet
=
'
_foo
'
;
controller
.
insert
(
codeSnippet
,
1
,
0
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
this._foo
\n
abc_foo
\n
def_foo
'
);
},
[
'
this._
'
,
'
abc
'
,
'
def_
'
]);
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
7
,
1
,
7
),
// primary at `this._`
new
Selection
(
2
,
4
,
2
,
4
),
new
Selection
(
3
,
6
,
3
,
6
)
]);
codeSnippet
=
'
._foo
'
;
controller
.
insert
(
codeSnippet
,
2
,
0
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
this._foo
\n
abc._foo
\n
def._foo
'
);
},
[
'
this._
'
,
'
abc
'
,
'
def._
'
]);
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
3
,
6
,
3
,
6
),
// primary at `def._`
new
Selection
(
1
,
7
,
1
,
7
),
new
Selection
(
2
,
4
,
2
,
4
),
]);
codeSnippet
=
'
._foo
'
;
controller
.
insert
(
codeSnippet
,
2
,
0
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
this._foo
\n
abc._foo
\n
def._foo
'
);
},
[
'
this._
'
,
'
abc
'
,
'
def._
'
]);
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
2
,
4
,
2
,
4
),
// primary at `abc`
new
Selection
(
3
,
6
,
3
,
6
),
new
Selection
(
1
,
7
,
1
,
7
),
]);
codeSnippet
=
'
._foo
'
;
controller
.
insert
(
codeSnippet
,
2
,
0
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
this._._foo
\n
a._foo
\n
def._._foo
'
);
},
[
'
this._
'
,
'
abc
'
,
'
def._
'
]);
});
test
(
'
Multiple cursor and overwriteBefore/After, #16277
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
5
,
1
,
5
),
new
Selection
(
2
,
5
,
2
,
5
),
]);
codeSnippet
=
'
document
'
;
controller
.
insert
(
codeSnippet
,
3
,
0
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
{document}
\n
{document && true}
'
);
},
[
'
{foo}
'
,
'
{foo && true}
'
]);
});
test
(
'
Insert snippet twice, #19449
'
,
()
=>
{
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
1
,
1
,
1
)
]);
codeSnippet
=
'
for (var ${1:i}=0; ${1:i}<len; ${1:i}++) { $0 }
'
;
controller
.
insert
(
codeSnippet
,
0
,
0
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
for (var i=0; i<len; i++) { }for (var i=0; i<len; i++) { }
'
);
},
[
'
for (var i=0; i<len; i++) { }
'
]);
snippetTest
((
editor
,
cursor
,
codeSnippet
,
controller
)
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
1
,
1
,
1
)
]);
codeSnippet
=
'
for (let ${1:i}=0; ${1:i}<len; ${1:i}++) { $0 }
'
;
controller
.
insert
(
codeSnippet
,
0
,
0
);
assert
.
equal
(
editor
.
getModel
().
getValue
(),
'
for (let i=0; i<len; i++) { }for (var i=0; i<len; i++) { }
'
);
},
[
'
for (var i=0; i<len; i++) { }
'
]);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录