Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
f8a959ae
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,发现更多精彩内容 >>
提交
f8a959ae
编写于
5月 26, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make final tabstops of nested snippets normal tabstop, #24855
上级
90a68e55
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
34 addition
and
31 deletion
+34
-31
src/vs/editor/contrib/snippet/browser/snippetController2.ts
src/vs/editor/contrib/snippet/browser/snippetController2.ts
+4
-6
src/vs/editor/contrib/snippet/browser/snippetSession.ts
src/vs/editor/contrib/snippet/browser/snippetSession.ts
+17
-12
src/vs/editor/contrib/snippet/test/browser/snippetController2.test.ts
...r/contrib/snippet/test/browser/snippetController2.test.ts
+2
-2
src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts
...ditor/contrib/snippet/test/browser/snippetSession.test.ts
+11
-11
未找到文件。
src/vs/editor/contrib/snippet/browser/snippetController2.ts
浏览文件 @
f8a959ae
...
...
@@ -35,13 +35,11 @@ class SnippetSessions {
}
get
isAtFirstPlaceholder
():
boolean
{
// return !this.empty && this._stack[0].isAtFirstPlaceholder;
return
this
.
_stack
.
every
(
s
=>
s
.
isAtFirstPlaceholder
);
}
get
isAtFinalPlaceholder
():
boolean
{
// return !this.empty && this._stack[0].isAtFinalPlaceholder;
return
this
.
_stack
.
every
(
s
=>
s
.
isAtFinalPlaceholder
);
return
!
this
.
empty
&&
this
.
_stack
[
0
].
isAtLastPlaceholder
;
}
get
isSelectionWithinPlaceholders
():
boolean
{
...
...
@@ -61,7 +59,7 @@ class SnippetSessions {
next
():
void
{
for
(
let
i
=
this
.
_stack
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
snippet
=
this
.
_stack
[
i
];
if
(
!
snippet
.
isAt
Final
Placeholder
)
{
if
(
!
snippet
.
isAt
Last
Placeholder
)
{
snippet
.
next
();
break
;
}
...
...
@@ -123,8 +121,8 @@ export class SnippetController2 {
}
const
snippet
=
new
SnippetSession
(
this
.
_editor
,
template
,
overwriteBefore
,
overwriteAfter
);
this
.
_sessions
.
add
(
snippet
);
snippet
.
insert
();
const
newLen
=
this
.
_sessions
.
add
(
snippet
);
snippet
.
insert
(
newLen
>
1
);
if
(
undoStopAfter
)
{
this
.
_editor
.
getModel
().
pushStackElement
();
...
...
src/vs/editor/contrib/snippet/browser/snippetSession.ts
浏览文件 @
f8a959ae
...
...
@@ -130,17 +130,11 @@ export class OneSnippet {
}
get
isAtFirstPlaceholder
()
{
return
this
.
_placeholderGroupsIdx
==
=
0
||
this
.
_placeholderGroups
.
length
===
0
;
return
this
.
_placeholderGroupsIdx
<
=
0
||
this
.
_placeholderGroups
.
length
===
0
;
}
get
isAtFinalPlaceholder
()
{
if
(
this
.
_placeholderGroups
.
length
===
0
)
{
return
true
;
}
else
if
(
this
.
_placeholderGroupsIdx
<
0
)
{
return
false
;
}
else
{
return
this
.
_placeholderGroups
[
this
.
_placeholderGroupsIdx
][
0
].
isFinalTabstop
;
}
get
isAtLastPlaceholder
()
{
return
this
.
_placeholderGroupsIdx
===
this
.
_placeholderGroups
.
length
-
1
;
}
get
hasPlaceholder
()
{
...
...
@@ -215,7 +209,7 @@ export class SnippetSession {
dispose
(
this
.
_snippets
);
}
insert
():
void
{
insert
(
ignoreFinalTabstops
:
boolean
=
false
):
void
{
const
model
=
this
.
_editor
.
getModel
();
const
edits
:
IIdentifiedSingleEditOperation
[]
=
[];
...
...
@@ -260,6 +254,17 @@ export class SnippetSession {
const
adjustedTemplate
=
SnippetSession
.
adjustWhitespace
(
model
,
start
,
this
.
_template
);
const
snippet
=
SnippetParser
.
parse
(
adjustedTemplate
).
resolveVariables
(
new
EditorSnippetVariableResolver
(
model
,
snippetSelection
));
// rewrite final-tabstop to some other placeholder because this
// snippet sits inside another snippet
if
(
ignoreFinalTabstops
)
{
for
(
const
placeholder
of
snippet
.
placeholders
)
{
if
(
placeholder
.
isFinalTabstop
)
{
placeholder
.
index
=
String
(
snippet
.
placeholders
.
length
);
}
}
}
const
offset
=
model
.
getOffsetAt
(
start
)
+
delta
;
delta
+=
snippet
.
text
.
length
-
model
.
getValueLengthInRange
(
snippetSelection
);
...
...
@@ -304,8 +309,8 @@ export class SnippetSession {
return
this
.
_snippets
[
0
].
isAtFirstPlaceholder
;
}
get
isAt
Final
Placeholder
()
{
return
this
.
_snippets
[
0
].
isAt
Final
Placeholder
;
get
isAt
Last
Placeholder
()
{
return
this
.
_snippets
[
0
].
isAt
Last
Placeholder
;
}
get
hasPlaceholder
()
{
...
...
src/vs/editor/contrib/snippet/test/browser/snippetController2.test.ts
浏览文件 @
f8a959ae
...
...
@@ -154,8 +154,8 @@ suite('SnippetController2', function () {
assertContextKeys
(
contextKeys
,
true
,
false
,
true
);
assertSelections
(
editor
,
new
Selection
(
1
,
1
,
1
,
7
),
new
Selection
(
2
,
5
,
2
,
11
));
ctrl
.
insert
(
'
far
boo$1
$0
'
);
assertSelections
(
editor
,
new
Selection
(
1
,
7
,
1
,
7
),
new
Selection
(
2
,
11
,
2
,
11
));
ctrl
.
insert
(
'
far
$1boo
$0
'
);
assertSelections
(
editor
,
new
Selection
(
1
,
4
,
1
,
4
),
new
Selection
(
2
,
8
,
2
,
8
));
assertContextKeys
(
contextKeys
,
true
,
false
,
true
);
ctrl
.
next
();
...
...
src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts
浏览文件 @
f8a959ae
...
...
@@ -257,22 +257,22 @@ suite('SnippetSession', function () {
editor
.
trigger
(
'
test
'
,
'
type
'
,
{
text
:
'
333
'
});
session
.
next
();
assert
.
equal
(
session
.
isAt
Final
Placeholder
,
true
);
assert
.
equal
(
session
.
isAt
Last
Placeholder
,
true
);
});
test
(
'
snippets, gracefully move over final tabstop
'
,
function
()
{
const
session
=
new
SnippetSession
(
editor
,
'
${1}bar$0
'
);
session
.
insert
();
assert
.
equal
(
session
.
isAt
Final
Placeholder
,
false
);
assert
.
equal
(
session
.
isAt
Last
Placeholder
,
false
);
assertSelections
(
editor
,
new
Selection
(
1
,
1
,
1
,
1
),
new
Selection
(
2
,
5
,
2
,
5
));
session
.
next
();
assert
.
equal
(
session
.
isAt
Final
Placeholder
,
true
);
assert
.
equal
(
session
.
isAt
Last
Placeholder
,
true
);
assertSelections
(
editor
,
new
Selection
(
1
,
4
,
1
,
4
),
new
Selection
(
2
,
8
,
2
,
8
));
session
.
next
();
assert
.
equal
(
session
.
isAt
Final
Placeholder
,
true
);
assert
.
equal
(
session
.
isAt
Last
Placeholder
,
true
);
assertSelections
(
editor
,
new
Selection
(
1
,
4
,
1
,
4
),
new
Selection
(
2
,
8
,
2
,
8
));
});
...
...
@@ -285,11 +285,11 @@ suite('SnippetSession', function () {
assert
.
equal
(
model
.
getValue
(),
'
log(XXX);function foo() {
\n
log(XXX);console.log(a);
\n
}
'
);
session
.
next
();
assert
.
equal
(
session
.
isAt
Final
Placeholder
,
false
);
assert
.
equal
(
session
.
isAt
Last
Placeholder
,
false
);
// assertSelections(editor, new Selection(1, 7, 1, 7), new Selection(2, 11, 2, 11));
session
.
next
();
assert
.
equal
(
session
.
isAt
Final
Placeholder
,
true
);
assert
.
equal
(
session
.
isAt
Last
Placeholder
,
true
);
assertSelections
(
editor
,
new
Selection
(
1
,
10
,
1
,
10
),
new
Selection
(
2
,
14
,
2
,
14
));
});
...
...
@@ -321,7 +321,7 @@ suite('SnippetSession', function () {
// reset selection to placeholder
session
.
next
();
assert
.
equal
(
session
.
isSelectionWithinPlaceholders
(),
true
);
assert
.
equal
(
session
.
isAt
Final
Placeholder
,
true
);
assert
.
equal
(
session
.
isAt
Last
Placeholder
,
true
);
assertSelections
(
editor
,
new
Selection
(
1
,
13
,
1
,
13
),
new
Selection
(
2
,
17
,
2
,
17
));
});
...
...
@@ -341,11 +341,11 @@ suite('SnippetSession', function () {
assertSelections
(
editor
,
new
Selection
(
1
,
6
,
1
,
10
));
second
.
next
();
assert
.
equal
(
second
.
isAt
Final
Placeholder
,
true
);
assert
.
equal
(
second
.
isAt
Last
Placeholder
,
true
);
assertSelections
(
editor
,
new
Selection
(
1
,
10
,
1
,
10
));
first
.
next
();
assert
.
equal
(
first
.
isAt
Final
Placeholder
,
true
);
assert
.
equal
(
first
.
isAt
Last
Placeholder
,
true
);
assertSelections
(
editor
,
new
Selection
(
1
,
13
,
1
,
13
));
});
...
...
@@ -353,7 +353,7 @@ suite('SnippetSession', function () {
const
session
=
new
SnippetSession
(
editor
,
'
farboo$0
'
);
session
.
insert
();
assert
.
equal
(
session
.
isAt
Final
Placeholder
,
true
);
assert
.
equal
(
session
.
isAt
Last
Placeholder
,
true
);
assert
.
equal
(
session
.
isSelectionWithinPlaceholders
(),
false
);
editor
.
trigger
(
'
test
'
,
'
type
'
,
{
text
:
'
XXX
'
});
...
...
@@ -368,7 +368,7 @@ suite('SnippetSession', function () {
editor
.
setSelection
(
new
Selection
(
1
,
2
,
1
,
2
));
assert
.
equal
(
session
.
isSelectionWithinPlaceholders
(),
false
);
assert
.
equal
(
session
.
isAt
Final
Placeholder
,
true
);
assert
.
equal
(
session
.
isAt
Last
Placeholder
,
true
);
editor
.
trigger
(
'
test
'
,
'
type
'
,
{
text
:
'
XXX
'
});
assert
.
equal
(
model
.
getLineContent
(
1
),
'
fXXXfarboounction foo() {
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录