Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
cf9a174b
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,发现更多精彩内容 >>
提交
cf9a174b
编写于
5月 10, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
start adding command and wireup with insert snippet
上级
f4a23ca7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
17 deletion
+58
-17
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
+6
-4
src/vs/editor/contrib/snippet/browser/snippetController2.ts
src/vs/editor/contrib/snippet/browser/snippetController2.ts
+49
-10
src/vs/editor/contrib/snippet/test/browser/snippetController2.test.ts
...r/contrib/snippet/test/browser/snippetController2.test.ts
+1
-1
src/vs/workbench/parts/snippets/electron-browser/insertSnippet.ts
...orkbench/parts/snippets/electron-browser/insertSnippet.ts
+2
-2
未找到文件。
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
浏览文件 @
cf9a174b
...
...
@@ -26,9 +26,10 @@ class OneSnippet {
private
_placeholderGroupsIdx
:
number
;
private
static
readonly
_decor
=
{
active
:
<
IModelDecorationOptions
>
{
stickiness
:
TrackedRangeStickiness
.
AlwaysGrowsWhenTypingAtEdges
},
activeFinal
:
<
IModelDecorationOptions
>
{
stickiness
:
TrackedRangeStickiness
.
NeverGrowsWhenTypingAtEdges
},
inactive
:
<
IModelDecorationOptions
>
{
stickiness
:
TrackedRangeStickiness
.
NeverGrowsWhenTypingAtEdges
},
active
:
<
IModelDecorationOptions
>
{
stickiness
:
TrackedRangeStickiness
.
AlwaysGrowsWhenTypingAtEdges
,
className
:
'
snippet-placeholder
'
},
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
},
};
...
...
@@ -73,7 +74,8 @@ class OneSnippet {
model
.
getPositionAt
(
this
.
_offset
+
placeholderOffset
),
model
.
getPositionAt
(
this
.
_offset
+
placeholderOffset
+
placeholderLen
)
);
const
handle
=
accessor
.
addDecoration
(
range
,
OneSnippet
.
_decor
.
inactive
);
const
options
=
placeholder
.
isFinalTabstop
?
OneSnippet
.
_decor
.
inactiveFinal
:
OneSnippet
.
_decor
.
inactive
;
const
handle
=
accessor
.
addDecoration
(
range
,
options
);
this
.
_placeholderDecorations
.
set
(
placeholder
,
handle
);
}
});
...
...
src/vs/editor/contrib/snippet/browser/snippetController2.ts
浏览文件 @
cf9a174b
...
...
@@ -5,17 +5,23 @@
'
use strict
'
;
import
{
RawContextKey
,
IContextKey
,
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
RawContextKey
,
IContextKey
,
IContextKeyService
,
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ICommonCodeEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
commonEditorContribution
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
commonEditorContribution
,
CommonEditorRegistry
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
dispose
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
SnippetSession
}
from
'
./editorSnippets
'
;
import
{
EditorCommand
}
from
"
vs/editor/common/config/config
"
;
import
{
EditorContextKeys
}
from
"
vs/editor/common/editorContextKeys
"
;
import
{
KeyCode
,
KeyMod
}
from
"
vs/base/common/keyCodes
"
;
@
commonEditorContribution
export
class
SnippetController2
{
static
InSnippetMode
=
new
RawContextKey
(
'
inSnippet
'
,
false
);
static
get
(
editor
:
ICommonCodeEditor
):
SnippetController2
{
return
editor
.
getContribution
<
SnippetController2
>
(
'
snippetController2
'
);
}
static
InSnippetMode
=
new
RawContextKey
(
'
isInSnippet
'
,
false
);
static
HasNextTabstop
=
new
RawContextKey
(
'
hasNextTabstop
'
,
false
);
static
HasPrevTabstop
=
new
RawContextKey
(
'
hasPrevTabstop
'
,
false
);
...
...
@@ -45,11 +51,9 @@ export class SnippetController2 {
}
insert
(
template
:
string
,
overwriteBefore
:
number
=
0
,
overwriteAfter
:
number
=
0
):
void
{
if
(
this
.
_snippet
)
{
this
.
abort
();
this
.
cancel
();
}
this
.
_snippet
=
new
SnippetSession
(
this
.
_editor
,
template
,
overwriteBefore
,
overwriteAfter
);
this
.
_snippetListener
=
[
this
.
_editor
.
onDidChangeCursorSelection
(()
=>
this
.
_updateState
())];
this
.
_snippet
.
insert
();
...
...
@@ -60,15 +64,15 @@ export class SnippetController2 {
return
;
}
if
(
this
.
_snippet
.
isAtFinalPlaceholder
||
!
this
.
_snippet
.
validateSelections
())
{
return
this
.
abort
();
return
this
.
cancel
();
}
this
.
_inSnippet
.
set
(
true
);
this
.
_hasPrevTabstop
.
set
(
!
this
.
_snippet
.
isAtFirstPlaceholder
);
this
.
_hasNextTabstop
.
set
(
!
this
.
_snippet
.
isAtFinalPlaceholder
);
this
.
_inSnippet
.
set
(
true
);
}
abort
():
void
{
cancel
():
void
{
if
(
this
.
_snippet
)
{
this
.
_hasPrevTabstop
.
reset
();
this
.
_hasNextTabstop
.
reset
();
...
...
@@ -94,3 +98,38 @@ export class SnippetController2 {
}
}
const
CommandCtor
=
EditorCommand
.
bindToContribution
<
SnippetController2
>
(
SnippetController2
.
get
);
CommonEditorRegistry
.
registerEditorCommand
(
new
CommandCtor
({
id
:
'
snippet.next
'
,
precondition
:
ContextKeyExpr
.
and
(
SnippetController2
.
InSnippetMode
,
SnippetController2
.
HasNextTabstop
),
handler
:
ctrl
=>
ctrl
.
next
(),
kbOpts
:
{
weight
:
CommonEditorRegistry
.
commandWeight
(
30
),
kbExpr
:
EditorContextKeys
.
textFocus
,
primary
:
KeyCode
.
Tab
}
}));
CommonEditorRegistry
.
registerEditorCommand
(
new
CommandCtor
({
id
:
'
snippet.prev
'
,
precondition
:
ContextKeyExpr
.
and
(
SnippetController2
.
InSnippetMode
,
SnippetController2
.
HasPrevTabstop
),
handler
:
ctrl
=>
ctrl
.
prev
(),
kbOpts
:
{
weight
:
CommonEditorRegistry
.
commandWeight
(
30
),
kbExpr
:
EditorContextKeys
.
textFocus
,
primary
:
KeyMod
.
Shift
|
KeyCode
.
Tab
}
}));
CommonEditorRegistry
.
registerEditorCommand
(
new
CommandCtor
({
id
:
'
snippet.cancel
'
,
precondition
:
SnippetController2
.
InSnippetMode
,
handler
:
ctrl
=>
ctrl
.
cancel
(),
kbOpts
:
{
weight
:
CommonEditorRegistry
.
commandWeight
(
30
),
kbExpr
:
EditorContextKeys
.
textFocus
,
primary
:
KeyCode
.
Escape
,
secondary
:
[
KeyMod
.
Shift
|
KeyCode
.
Escape
]
}
}));
src/vs/editor/contrib/snippet/test/browser/snippetController2.test.ts
浏览文件 @
cf9a174b
...
...
@@ -57,7 +57,7 @@ suite('SnippetController2', function () {
assertContextKeys
(
contextKeys
,
true
,
false
,
true
);
assertSelections
(
editor
,
new
Selection
(
1
,
4
,
1
,
7
),
new
Selection
(
2
,
8
,
2
,
11
));
ctrl
.
abort
();
ctrl
.
cancel
();
assertContextKeys
(
contextKeys
,
false
,
false
,
false
);
assertSelections
(
editor
,
new
Selection
(
1
,
4
,
1
,
7
),
new
Selection
(
2
,
8
,
2
,
11
));
});
...
...
src/vs/workbench/parts/snippets/electron-browser/insertSnippet.ts
浏览文件 @
cf9a174b
...
...
@@ -8,12 +8,12 @@ import * as nls from 'vs/nls';
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ICommonCodeEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
editorAction
,
ServicesAccessor
,
EditorAction
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
SnippetController
}
from
'
vs/editor/contrib/snippet/common/snippetController
'
;
import
{
IQuickOpenService
,
IPickOpenEntry
}
from
'
vs/platform/quickOpen/common/quickOpen
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
LanguageId
}
from
'
vs/editor/common/modes
'
;
import
{
ICommandService
,
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
ISnippetsService
,
ISnippet
}
from
'
vs/workbench/parts/snippets/electron-browser/snippetsService
'
;
import
{
SnippetController2
}
from
'
vs/editor/contrib/snippet/browser/snippetController2
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
interface
ISnippetPick
extends
IPickOpenEntry
{
...
...
@@ -128,7 +128,7 @@ class InsertSnippetAction extends EditorAction {
}
}).
then
(
snippet
=>
{
if
(
snippet
)
{
SnippetController
.
get
(
editor
).
insertSnippe
t
(
snippet
.
codeSnippet
,
0
,
0
);
SnippetController
2
.
get
(
editor
).
inser
t
(
snippet
.
codeSnippet
,
0
,
0
);
}
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录