Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a284f0aa
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,发现更多精彩内容 >>
提交
a284f0aa
编写于
12月 13, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
align snippets/selections and clipboard lines, #40153
上级
bef346d6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
15 deletion
+57
-15
src/vs/editor/contrib/snippet/snippetSession.ts
src/vs/editor/contrib/snippet/snippetSession.ts
+4
-4
src/vs/editor/contrib/snippet/snippetVariables.ts
src/vs/editor/contrib/snippet/snippetVariables.ts
+19
-5
src/vs/editor/contrib/snippet/test/snippetVariables.test.ts
src/vs/editor/contrib/snippet/test/snippetVariables.test.ts
+34
-6
未找到文件。
src/vs/editor/contrib/snippet/snippetSession.ts
浏览文件 @
a284f0aa
...
...
@@ -272,7 +272,7 @@ export class SnippetSession {
const
snippets
:
OneSnippet
[]
=
[];
const
modelBasedVariableResolver
=
new
ModelBasedVariableResolver
(
model
);
const
clipboard
VariableResolver
=
new
ClipboardBasedVariableResolver
(
editor
.
invokeWithinContext
(
accessor
=>
accessor
.
get
(
IClipboardService
,
optional
)
));
const
clipboard
Service
=
editor
.
invokeWithinContext
(
accessor
=>
accessor
.
get
(
IClipboardService
,
optional
));
let
delta
=
0
;
...
...
@@ -286,11 +286,11 @@ export class SnippetSession {
// the original index. that allows you to create correct
// offset-based selection logic without changing the
// primary selection
const
indexedSelection
=
editor
.
getSelections
()
const
indexedSelection
s
=
editor
.
getSelections
()
.
map
((
selection
,
idx
)
=>
({
selection
,
idx
}))
.
sort
((
a
,
b
)
=>
Range
.
compareRangesUsingStarts
(
a
.
selection
,
b
.
selection
));
for
(
const
{
selection
,
idx
}
of
indexedSelection
)
{
for
(
const
{
selection
,
idx
}
of
indexedSelection
s
)
{
// extend selection with the `overwriteBefore` and `overwriteAfter` and then
// compare if this matches the extensions of the primary selection
...
...
@@ -317,7 +317,7 @@ export class SnippetSession {
.
parse
(
adjustedTemplate
,
true
,
enforceFinalTabstop
)
.
resolveVariables
(
new
CompositeSnippetVariableResolver
([
modelBasedVariableResolver
,
clipboardVariableResolver
,
new
ClipboardBasedVariableResolver
(
clipboardService
,
idx
,
indexedSelections
.
length
)
,
new
SelectionBasedVariableResolver
(
model
,
selection
)
]));
...
...
src/vs/editor/contrib/snippet/snippetVariables.ts
浏览文件 @
a284f0aa
...
...
@@ -9,7 +9,7 @@ import { basename, dirname } from 'vs/base/common/paths';
import
{
IModel
}
from
'
vs/editor/common/editorCommon
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
VariableResolver
,
Variable
,
Text
}
from
'
vs/editor/contrib/snippet/snippetParser
'
;
import
{
getLeadingWhitespace
,
commonPrefixLength
}
from
'
vs/base/common/strings
'
;
import
{
getLeadingWhitespace
,
commonPrefixLength
,
isFalsyOrWhitespace
}
from
'
vs/base/common/strings
'
;
import
{
IClipboardService
}
from
'
vs/platform/clipboard/common/clipboardService
'
;
export
const
KnownSnippetVariableNames
=
Object
.
freeze
({
...
...
@@ -145,14 +145,28 @@ export class ModelBasedVariableResolver implements VariableResolver {
export
class
ClipboardBasedVariableResolver
implements
VariableResolver
{
constructor
(
private
readonly
_clipboardService
:
IClipboardService
private
readonly
_clipboardService
:
IClipboardService
,
private
readonly
_selectionIdx
:
number
,
private
readonly
_selectionCount
:
number
)
{
//
}
resolve
(
variable
:
Variable
):
string
{
return
(
variable
.
name
===
'
CLIPBOARD
'
&&
this
.
_clipboardService
)
?
this
.
_clipboardService
.
readText
()
||
undefined
:
undefined
;
if
(
variable
.
name
!==
'
CLIPBOARD
'
||
!
this
.
_clipboardService
)
{
return
undefined
;
}
const
text
=
this
.
_clipboardService
.
readText
();
if
(
!
text
)
{
return
undefined
;
}
const
lines
=
text
.
split
(
/
\r\n
|
\n
|
\r
/
).
filter
(
s
=>
!
isFalsyOrWhitespace
(
s
));
if
(
lines
.
length
===
this
.
_selectionCount
)
{
return
lines
[
this
.
_selectionIdx
];
}
else
{
return
text
;
}
}
}
src/vs/editor/contrib/snippet/test/snippetVariables.test.ts
浏览文件 @
a284f0aa
...
...
@@ -208,15 +208,17 @@ suite('Snippet Variables Resolver', function () {
});
test
(
'
Add variable to insert value from clipboard to a snippet #40153
'
,
function
()
{
let
readTextResult
:
string
;
let
_throw
=
()
=>
{
throw
new
Error
();
};
let
resolver
=
new
ClipboardBasedVariableResolver
(
new
class
implements
IClipboardService
{
const
clipboardService
=
new
class
implements
IClipboardService
{
_serviceBrand
:
any
;
readText
():
string
{
return
readTextResult
;
}
writeText
=
_throw
;
readFindText
=
_throw
;
writeFindText
=
_throw
;
});
_throw
=
()
=>
{
throw
new
Error
();
};
writeText
=
this
.
_throw
;
readFindText
=
this
.
_throw
;
writeFindText
=
this
.
_throw
;
};
let
resolver
=
new
ClipboardBasedVariableResolver
(
clipboardService
,
1
,
0
);
readTextResult
=
undefined
;
assertVariableResolve
(
resolver
,
'
CLIPBOARD
'
,
undefined
);
...
...
@@ -233,4 +235,30 @@ suite('Snippet Variables Resolver', function () {
assertVariableResolve
(
resolver
,
'
foo
'
,
undefined
);
assertVariableResolve
(
resolver
,
'
cLIPBOARD
'
,
undefined
);
});
test
(
'
Add variable to insert value from clipboard to a snippet #40153
'
,
function
()
{
let
readTextResult
:
string
;
let
resolver
:
VariableResolver
;
const
clipboardService
=
new
class
implements
IClipboardService
{
_serviceBrand
:
any
;
readText
():
string
{
return
readTextResult
;
}
_throw
=
()
=>
{
throw
new
Error
();
};
writeText
=
this
.
_throw
;
readFindText
=
this
.
_throw
;
writeFindText
=
this
.
_throw
;
};
resolver
=
new
ClipboardBasedVariableResolver
(
clipboardService
,
1
,
2
);
readTextResult
=
'
line1
'
;
assertVariableResolve
(
resolver
,
'
CLIPBOARD
'
,
'
line1
'
);
readTextResult
=
'
line1
\n
line2
\n
line3
'
;
assertVariableResolve
(
resolver
,
'
CLIPBOARD
'
,
'
line1
\n
line2
\n
line3
'
);
readTextResult
=
'
line1
\n
line2
'
;
assertVariableResolve
(
resolver
,
'
CLIPBOARD
'
,
'
line2
'
);
readTextResult
=
'
line1
\n
line2
'
;
resolver
=
new
ClipboardBasedVariableResolver
(
clipboardService
,
0
,
2
);
assertVariableResolve
(
resolver
,
'
CLIPBOARD
'
,
'
line1
'
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录