Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
403d7841
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,发现更多精彩内容 >>
提交
403d7841
编写于
5月 11, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
be a little stricter and leave snippet mode when cursor move out of placeholders
上级
36f3b136
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
37 deletion
+49
-37
src/vs/editor/contrib/snippet/browser/snippetController2.ts
src/vs/editor/contrib/snippet/browser/snippetController2.ts
+3
-2
src/vs/editor/contrib/snippet/browser/snippetSession.ts
src/vs/editor/contrib/snippet/browser/snippetSession.ts
+35
-24
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
浏览文件 @
403d7841
...
...
@@ -57,11 +57,12 @@ export class SnippetController2 {
this
.
cancel
();
}
this
.
_snippet
=
new
SnippetSession
(
this
.
_editor
,
template
,
overwriteBefore
,
overwriteAfter
);
this
.
_snippet
.
insert
();
this
.
_snippetListener
=
[
this
.
_editor
.
onDidChangeModel
(()
=>
this
.
cancel
()),
this
.
_editor
.
onDidChangeCursorSelection
(()
=>
this
.
_updateState
())
];
this
.
_
snippet
.
insert
();
this
.
_
updateState
();
}
private
_updateState
():
void
{
...
...
@@ -76,7 +77,7 @@ export class SnippetController2 {
return
;
}
if
(
this
.
_snippet
.
isAtFinalPlaceholder
||
!
this
.
_snippet
.
validateSelection
s
())
{
if
(
this
.
_snippet
.
isAtFinalPlaceholder
||
!
this
.
_snippet
.
isSelectionWithPlaceholder
s
())
{
return
this
.
cancel
();
}
...
...
src/vs/editor/contrib/snippet/browser/snippetSession.ts
浏览文件 @
403d7841
...
...
@@ -21,7 +21,6 @@ class OneSnippet {
private
readonly
_snippet
:
TextmateSnippet
;
private
readonly
_offset
:
number
;
private
_snippetDecoration
:
string
;
private
_placeholderDecorations
:
Map
<
Placeholder
,
string
>
;
private
_placeholderGroups
:
Placeholder
[][];
private
_placeholderGroupsIdx
:
number
;
...
...
@@ -31,7 +30,6 @@ class OneSnippet {
inactive
:
<
IModelDecorationOptions
>
{
stickiness
:
TrackedRangeStickiness
.
NeverGrowsWhenTypingAtEdges
,
className
:
'
snippet-placeholder
'
},
activeFinal
:
<
IModelDecorationOptions
>
{
stickiness
:
TrackedRangeStickiness
.
NeverGrowsWhenTypingAtEdges
,
className
:
'
finish-snippet-placeholder
'
},
inactiveFinal
:
<
IModelDecorationOptions
>
{
stickiness
:
TrackedRangeStickiness
.
NeverGrowsWhenTypingAtEdges
,
className
:
'
finish-snippet-placeholder
'
},
snippet
:
<
IModelDecorationOptions
>
{
stickiness
:
TrackedRangeStickiness
.
NeverGrowsWhenTypingAtEdges
},
};
constructor
(
editor
:
ICommonCodeEditor
,
snippet
:
TextmateSnippet
,
offset
:
number
)
{
...
...
@@ -60,13 +58,6 @@ class OneSnippet {
this
.
_editor
.
changeDecorations
(
accessor
=>
{
// create one decoration for the whole snippets
const
range
=
Range
.
fromPositions
(
model
.
getPositionAt
(
this
.
_offset
),
model
.
getPositionAt
(
this
.
_offset
+
this
.
_snippet
.
text
.
length
)
);
this
.
_snippetDecoration
=
accessor
.
addDecoration
(
range
,
OneSnippet
.
_decor
.
snippet
);
// create a decoration for each placeholder
for
(
const
placeholder
of
this
.
_snippet
.
placeholders
)
{
const
placeholderOffset
=
this
.
_snippet
.
offset
(
placeholder
);
...
...
@@ -151,8 +142,17 @@ class OneSnippet {
return
this
.
_snippet
.
placeholders
.
length
>
0
;
}
get
range
()
{
return
this
.
_snippetDecoration
!==
undefined
&&
this
.
_editor
.
getModel
().
getDecorationRange
(
this
.
_snippetDecoration
);
get
placeholderRanges
()
{
const
ret
:
Range
[]
=
[];
this
.
_placeholderDecorations
.
forEach
((
id
,
placeholder
)
=>
{
if
(
!
placeholder
.
isFinalTabstop
)
{
const
range
=
this
.
_editor
.
getModel
().
getDecorationRange
(
id
);
if
(
range
)
{
ret
.
push
(
range
);
}
}
});
return
ret
;
}
}
...
...
@@ -307,27 +307,38 @@ export class SnippetSession {
return
this
.
_snippets
[
0
].
hasPlaceholder
;
}
validateSelection
s
():
boolean
{
isSelectionWithPlaceholder
s
():
boolean
{
const
selections
=
this
.
_editor
.
getSelections
();
if
(
selections
.
length
<
this
.
_snippets
.
length
)
{
// this means we started snippet mode with N
// selections and have M (N > M) selections.
// So one snippet is without selection -> cancel
return
false
;
}
for
(
const
selection
of
selections
)
{
let
found
=
false
;
for
(
const
{
range
}
of
this
.
_snippets
)
{
if
(
!
range
)
{
// all deleted
return
false
;
}
const
ranges
:
Range
[]
=
[];
for
(
const
snippet
of
this
.
_snippets
)
{
ranges
.
push
(...
snippet
.
placeholderRanges
);
}
if
(
selections
.
length
>
ranges
.
length
)
{
return
false
;
}
// sort selections and ranges by their start position
// and then make sure each selection is contained by
// a placeholder range
selections
.
sort
(
Range
.
compareRangesUsingStarts
);
ranges
.
sort
(
Range
.
compareRangesUsingStarts
);
outer
:
for
(
const
selection
of
selections
)
{
let
range
:
Range
;
while
(
range
=
ranges
.
shift
())
{
if
(
range
.
containsRange
(
selection
))
{
found
=
true
;
break
;
continue
outer
;
}
}
if
(
!
found
)
{
return
false
;
}
return
false
;
}
return
true
;
...
...
src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts
浏览文件 @
403d7841
...
...
@@ -299,28 +299,28 @@ suite('SnippetSession', function () {
assert
.
equal
(
model
.
getValue
(),
'
foofarboobarfunction foo() {
\n
foofarboobarconsole.log(a);
\n
}
'
);
assertSelections
(
editor
,
new
Selection
(
1
,
1
,
1
,
4
),
new
Selection
(
2
,
5
,
2
,
8
));
assert
.
equal
(
session
.
validateSelection
s
(),
true
);
assert
.
equal
(
session
.
isSelectionWithPlaceholder
s
(),
true
);
editor
.
setSelections
([
new
Selection
(
1
,
1
,
1
,
1
)]);
assert
.
equal
(
session
.
validateSelection
s
(),
false
);
assert
.
equal
(
session
.
isSelectionWithPlaceholder
s
(),
false
);
editor
.
setSelections
([
new
Selection
(
1
,
6
,
1
,
6
),
new
Selection
(
2
,
10
,
2
,
10
)]);
assert
.
equal
(
session
.
validateSelections
(),
true
);
assert
.
equal
(
session
.
isSelectionWithPlaceholders
(),
false
);
// in snippet, outside placeholder
editor
.
setSelections
([
new
Selection
(
1
,
6
,
1
,
6
),
new
Selection
(
2
,
10
,
2
,
10
),
new
Selection
(
1
,
1
,
1
,
1
)]);
assert
.
equal
(
session
.
validateSelections
(),
true
);
assert
.
equal
(
session
.
isSelectionWithPlaceholders
(),
false
);
// in snippet, outside placeholder
editor
.
setSelections
([
new
Selection
(
1
,
6
,
1
,
6
),
new
Selection
(
2
,
10
,
2
,
10
),
new
Selection
(
2
,
20
,
2
,
21
)]);
assert
.
equal
(
session
.
validateSelection
s
(),
false
);
assert
.
equal
(
session
.
isSelectionWithPlaceholder
s
(),
false
);
// reset selection to placeholder
session
.
next
();
assert
.
equal
(
session
.
validateSelection
s
(),
true
);
assert
.
equal
(
session
.
isSelectionWithPlaceholder
s
(),
true
);
assertSelections
(
editor
,
new
Selection
(
1
,
10
,
1
,
13
),
new
Selection
(
2
,
14
,
2
,
17
));
// reset selection to placeholder
session
.
next
();
assert
.
equal
(
session
.
validateSelection
s
(),
true
);
assert
.
equal
(
session
.
isSelectionWithPlaceholder
s
(),
true
);
assert
.
equal
(
session
.
isAtFinalPlaceholder
,
true
);
assertSelections
(
editor
,
new
Selection
(
1
,
13
,
1
,
13
),
new
Selection
(
2
,
17
,
2
,
17
));
});
...
...
@@ -354,10 +354,10 @@ suite('SnippetSession', function () {
const
session
=
new
SnippetSession
(
editor
,
'
farboo$0
'
);
session
.
insert
();
assert
.
equal
(
session
.
isAtFinalPlaceholder
,
true
);
assert
.
equal
(
session
.
validateSelections
(),
tru
e
);
assert
.
equal
(
session
.
isSelectionWithPlaceholders
(),
fals
e
);
editor
.
trigger
(
'
test
'
,
'
type
'
,
{
text
:
'
XXX
'
});
assert
.
equal
(
session
.
validateSelection
s
(),
false
);
assert
.
equal
(
session
.
isSelectionWithPlaceholder
s
(),
false
);
});
test
(
'
snippets, typing at beginning
'
,
function
()
{
...
...
@@ -367,12 +367,12 @@ suite('SnippetSession', function () {
session
.
insert
();
editor
.
setSelection
(
new
Selection
(
1
,
2
,
1
,
2
));
assert
.
equal
(
session
.
validateSelections
(),
tru
e
);
assert
.
equal
(
session
.
isSelectionWithPlaceholders
(),
fals
e
);
assert
.
equal
(
session
.
isAtFinalPlaceholder
,
true
);
editor
.
trigger
(
'
test
'
,
'
type
'
,
{
text
:
'
XXX
'
});
assert
.
equal
(
model
.
getLineContent
(
1
),
'
fXXXfarboounction foo() {
'
);
assert
.
equal
(
session
.
validateSelections
(),
tru
e
);
assert
.
equal
(
session
.
isSelectionWithPlaceholders
(),
fals
e
);
session
.
next
();
assertSelections
(
editor
,
new
Selection
(
1
,
11
,
1
,
11
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录