Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
6bbff65c
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,发现更多精彩内容 >>
提交
6bbff65c
编写于
5月 10, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support insert none snippet text
上级
ead17dea
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
54 addition
and
3 deletion
+54
-3
src/vs/editor/common/core/selection.ts
src/vs/editor/common/core/selection.ts
+9
-1
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
+16
-1
src/vs/editor/contrib/snippet/browser/snippetController2.ts
src/vs/editor/contrib/snippet/browser/snippetController2.ts
+9
-1
src/vs/editor/contrib/snippet/test/browser/editorSnippets.test.ts
...ditor/contrib/snippet/test/browser/editorSnippets.test.ts
+7
-0
src/vs/editor/contrib/snippet/test/browser/snippetController2.test.ts
...r/contrib/snippet/test/browser/snippetController2.test.ts
+9
-0
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+4
-0
未找到文件。
src/vs/editor/common/core/selection.ts
浏览文件 @
6bbff65c
...
...
@@ -5,6 +5,7 @@
'
use strict
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
/**
* A selection in the editor.
...
...
@@ -140,6 +141,13 @@ export class Selection extends Range {
// ----
/**
* Create a `Selection` from one or two positions
*/
public
static
fromPositions
(
start
:
IPosition
,
end
:
IPosition
=
start
):
Selection
{
return
new
Selection
(
start
.
lineNumber
,
start
.
column
,
end
.
lineNumber
,
end
.
column
);
}
/**
* Create a `Selection` from an `ISelection`.
*/
...
...
@@ -192,4 +200,4 @@ export class Selection extends Range {
return
new
Selection
(
endLineNumber
,
endColumn
,
startLineNumber
,
startColumn
);
}
}
\ No newline at end of file
}
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
浏览文件 @
6bbff65c
...
...
@@ -146,6 +146,10 @@ class OneSnippet {
}
}
get
hasPlaceholder
()
{
return
this
.
_snippet
.
getPlaceholders
().
length
>
0
;
}
get
range
()
{
return
this
.
_snippetDecoration
!==
undefined
&&
this
.
_editor
.
getModel
().
getDecorationRange
(
this
.
_snippetDecoration
);
}
...
...
@@ -204,6 +208,7 @@ export class SnippetSession {
}
insert
():
void
{
let
delta
=
0
;
let
edits
:
IIdentifiedSingleEditOperation
[]
=
[];
let
model
=
this
.
_editor
.
getModel
();
...
...
@@ -231,7 +236,13 @@ export class SnippetSession {
}
// make insert edit and start with first selections
const
newSelections
=
model
.
pushEditOperations
(
this
.
_editor
.
getSelections
(),
edits
,
()
=>
this
.
_move
(
true
));
const
newSelections
=
model
.
pushEditOperations
(
this
.
_editor
.
getSelections
(),
edits
,
undoEdits
=>
{
if
(
this
.
_snippets
[
0
].
hasPlaceholder
)
{
return
this
.
_move
(
true
);
}
else
{
return
undoEdits
.
map
(
edit
=>
Selection
.
fromPositions
(
edit
.
range
.
getEndPosition
()));
}
});
this
.
_editor
.
setSelections
(
newSelections
);
}
...
...
@@ -262,6 +273,10 @@ export class SnippetSession {
return
this
.
_snippets
[
0
].
isAtFinalPlaceholder
;
}
get
hasPlaceholder
()
{
return
this
.
_snippets
[
0
].
hasPlaceholder
;
}
validateSelections
():
boolean
{
const
selections
=
this
.
_editor
.
getSelections
();
if
(
selections
.
length
<
this
.
_snippets
.
length
)
{
...
...
src/vs/editor/contrib/snippet/browser/snippetController2.ts
浏览文件 @
6bbff65c
...
...
@@ -61,8 +61,16 @@ export class SnippetController2 {
private
_updateState
():
void
{
if
(
!
this
.
_snippet
)
{
// canceled in the meanwhile
return
;
}
if
(
!
this
.
_snippet
.
hasPlaceholder
)
{
// don't listen for selection changes and don't
// update context keys when the snippet is plain text
return
;
}
if
(
this
.
_snippet
.
isAtFinalPlaceholder
||
!
this
.
_snippet
.
validateSelections
())
{
return
this
.
cancel
();
}
...
...
@@ -74,9 +82,9 @@ export class SnippetController2 {
cancel
():
void
{
if
(
this
.
_snippet
)
{
this
.
_inSnippet
.
reset
();
this
.
_hasPrevTabstop
.
reset
();
this
.
_hasNextTabstop
.
reset
();
this
.
_inSnippet
.
reset
();
dispose
(
this
.
_snippetListener
);
dispose
(
this
.
_snippet
);
this
.
_snippet
=
undefined
;
...
...
src/vs/editor/contrib/snippet/test/browser/editorSnippets.test.ts
浏览文件 @
6bbff65c
...
...
@@ -99,6 +99,13 @@ suite('SnippetSession', function () {
);
});
test
(
'
snippets, just text
'
,
function
()
{
const
session
=
new
SnippetSession
(
editor
,
'
foobar
'
);
session
.
insert
();
assert
.
equal
(
model
.
getValue
(),
'
foobarfunction foo() {
\n
foobarconsole.log(a);
\n
}
'
);
assertSelections
(
editor
,
new
Selection
(
1
,
7
,
1
,
7
),
new
Selection
(
2
,
11
,
2
,
11
));
});
test
(
'
snippets, selections and new text with newlines
'
,
()
=>
{
const
session
=
new
SnippetSession
(
editor
,
'
foo
\n\t
${1:bar}
\n
$0
'
);
...
...
src/vs/editor/contrib/snippet/test/browser/snippetController2.test.ts
浏览文件 @
6bbff65c
...
...
@@ -116,6 +116,15 @@ suite('SnippetController2', function () {
assertContextKeys
(
contextKeys
,
false
,
false
,
false
);
});
test
(
'
insert, insert plain text -> no snippet mode
'
,
function
()
{
const
ctrl
=
new
SnippetController2
(
editor
,
contextKeys
);
ctrl
.
insert
(
'
foobar
'
);
assertContextKeys
(
contextKeys
,
false
,
false
,
false
);
assertSelections
(
editor
,
new
Selection
(
1
,
7
,
1
,
7
),
new
Selection
(
2
,
11
,
2
,
11
));
});
test
(
'
insert, delete snippet text
'
,
function
()
{
const
ctrl
=
new
SnippetController2
(
editor
,
contextKeys
);
...
...
src/vs/monaco.d.ts
浏览文件 @
6bbff65c
...
...
@@ -726,6 +726,10 @@ declare module monaco {
* Create a new selection with a different `selectionStartLineNumber` and `selectionStartColumn`.
*/
setStartPosition
(
startLineNumber
:
number
,
startColumn
:
number
):
Selection
;
/**
* Create a `Selection` from one or two positions
*/
static
fromPositions
(
start
:
IPosition
,
end
?:
IPosition
):
Selection
;
/**
* Create a `Selection` from an `ISelection`.
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录