Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
01c6d17c
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,发现更多精彩内容 >>
提交
01c6d17c
编写于
7月 25, 2017
作者:
R
Ramya Achutha Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tests for Expand Abbreviation
上级
0f70188d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
145 addition
and
8 deletion
+145
-8
extensions/emmet/src/abbreviationActions.ts
extensions/emmet/src/abbreviationActions.ts
+9
-8
extensions/emmet/src/test/abbreviationAction.test.ts
extensions/emmet/src/test/abbreviationAction.test.ts
+136
-0
未找到文件。
extensions/emmet/src/abbreviationActions.ts
浏览文件 @
01c6d17c
...
...
@@ -143,7 +143,7 @@ export function expandAbbreviation(args) {
abbreviationList
.
push
({
syntax
,
abbreviation
,
rangeToReplace
});
});
expandAbbreviationInRange
(
editor
,
abbreviationList
,
allAbbreviationsSame
);
return
expandAbbreviationInRange
(
editor
,
abbreviationList
,
allAbbreviationsSame
);
}
...
...
@@ -191,7 +191,7 @@ export function isValidLocationForEmmetAbbreviation(currentNode: Node, syntax: s
* @param expandAbbrList
* @param insertSameSnippet
*/
function
expandAbbreviationInRange
(
editor
:
vscode
.
TextEditor
,
expandAbbrList
:
ExpandAbbreviationInput
[],
insertSameSnippet
:
boolean
)
{
function
expandAbbreviationInRange
(
editor
:
vscode
.
TextEditor
,
expandAbbrList
:
ExpandAbbreviationInput
[],
insertSameSnippet
:
boolean
)
:
Thenable
<
boolean
>
{
if
(
!
expandAbbrList
||
expandAbbrList
.
length
===
0
)
{
return
;
}
...
...
@@ -200,14 +200,15 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex
// Snippet to replace at multiple cursors are not the same
// `editor.insertSnippet` will have to be called for each instance separately
// We will not be able to maintain multiple cursors after snippet insertion
let
insertPromises
=
[];
if
(
!
insertSameSnippet
)
{
expandAbbrList
.
forEach
((
expandAbbrInput
:
ExpandAbbreviationInput
)
=>
{
let
expandedText
=
expandAbbr
(
expandAbbrInput
,
newLine
);
if
(
expandedText
)
{
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
expandedText
),
expandAbbrInput
.
rangeToReplace
);
insertPromises
.
push
(
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
expandedText
),
expandAbbrInput
.
rangeToReplace
)
);
}
});
return
;
return
Promise
.
all
(
insertPromises
).
then
(()
=>
Promise
.
resolve
(
true
))
;
}
// Snippet to replace at all cursors are the same
...
...
@@ -219,7 +220,7 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex
return
new
vscode
.
Range
(
value
.
rangeToReplace
.
start
.
line
,
value
.
rangeToReplace
.
start
.
character
,
value
.
rangeToReplace
.
end
.
line
,
value
.
rangeToReplace
.
end
.
character
);
});
if
(
expandedText
)
{
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
expandedText
),
allRanges
);
return
editor
.
insertSnippet
(
new
vscode
.
SnippetString
(
expandedText
),
allRanges
);
}
}
...
...
@@ -232,7 +233,7 @@ function expandAbbr(input: ExpandAbbreviationInput, newLine: string): string {
const
expandOptions
=
getExpandOptions
(
emmetConfig
[
'
syntaxProfiles
'
],
emmetConfig
[
'
variables
'
],
input
.
syntax
,
input
.
textToWrap
);
// Below fixes https://github.com/Microsoft/vscode/issues/29898
// With this, Emmet formats inline elements as block elements
// With this, Emmet formats inline elements as block elements
// ensuring the wrapped multi line text does not get merged to a single line
if
(
input
.
textToWrap
&&
!
input
.
rangeToReplace
.
isSingleLine
)
{
expandOptions
.
profile
[
'
inlineBreak
'
]
=
1
;
...
...
@@ -286,8 +287,8 @@ function getSyntaxFromArgs(args: any): string {
}
const
mappedModes
=
getMappingForIncludedLanguages
();
let
language
:
string
=
(
typeof
args
!==
'
object
'
||
!
args
[
'
language
'
])
?
editor
.
document
.
languageId
:
args
[
'
language
'
];
let
parentMode
:
string
=
typeof
args
===
'
object
'
?
args
[
'
parentMode
'
]
:
undefined
;
let
language
:
string
=
(
!
args
||
typeof
args
!==
'
object
'
||
!
args
[
'
language
'
])
?
editor
.
document
.
languageId
:
args
[
'
language
'
];
let
parentMode
:
string
=
(
args
&&
typeof
args
===
'
object
'
)
?
args
[
'
parentMode
'
]
:
undefined
;
let
excludedLanguages
=
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
)[
'
exlcudeLanguages
'
]
?
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
)[
'
exlcudeLanguages
'
]
:
[];
let
syntax
=
getEmmetMode
((
mappedModes
[
language
]
?
mappedModes
[
language
]
:
language
),
excludedLanguages
);
if
(
syntax
)
{
...
...
extensions/emmet/src/test/abbreviationAction.test.ts
0 → 100644
浏览文件 @
01c6d17c
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
{
Selection
}
from
'
vscode
'
;
import
{
withRandomFileEditor
,
closeAllEditors
}
from
'
./testUtils
'
;
import
{
expandAbbreviation
}
from
'
../abbreviationActions
'
;
const
cssContents
=
`
.boo {
margin: 20px 10px;
background-image: url('tryme.png');
m10
}
.boo .hoo {
margin: 10px;
ind
}
`
;
const
scssContents
=
`
.boo {
margin: 20px 10px;
background-image: url('tryme.png');
.boo .hoo {
margin: 10px;
}
}
`
;
const
htmlContents
=
`
<body class="header">
<ul class="nav main">
<li class="item1">img</li>
<li class="item2">hithere</li>
ul>li
ul>li*2
ul>li.item$*2
ul>li.item$@44*2
<div
</ul>
<style>
.boo {
m10
}
</style>
</body>
`
;
suite
(
'
Tests for Expand Abbreviations (HTML)
'
,
()
=>
{
teardown
(
closeAllEditors
);
test
(
'
Expand snippets (HTML)
'
,
()
=>
{
return
testHtmlExpandAbbreviation
(
new
Selection
(
3
,
23
,
3
,
23
),
'
img
'
,
'
<img src=
\
"
\
" alt=
\
"
\
">
'
);
});
test
(
'
Expand abbreviation (HTML)
'
,
()
=>
{
return
testHtmlExpandAbbreviation
(
new
Selection
(
5
,
25
,
5
,
25
),
'
ul>li
'
,
'
<ul>
\n\t\t\t
<li></li>
\n\t\t
</ul>
'
);
});
test
(
'
Expand text that is neither an abbreviation nor a snippet to tags (HTML)
'
,
()
=>
{
return
testHtmlExpandAbbreviation
(
new
Selection
(
4
,
20
,
4
,
27
),
'
hithere
'
,
'
<hithere></hithere>
'
);
});
test
(
'
Expand abbreviation with repeaters (HTML)
'
,
()
=>
{
return
testHtmlExpandAbbreviation
(
new
Selection
(
6
,
27
,
6
,
27
),
'
ul>li*2
'
,
'
<ul>
\n\t\t\t
<li></li>
\n\t\t\t
<li></li>
\n\t\t
</ul>
'
);
});
test
(
'
Expand abbreviation with numbered repeaters (HTML)
'
,
()
=>
{
return
testHtmlExpandAbbreviation
(
new
Selection
(
7
,
33
,
7
,
33
),
'
ul>li.item$*2
'
,
'
<ul>
\n\t\t\t
<li class="item1"></li>
\n\t\t\t
<li class="item2"></li>
\n\t\t
</ul>
'
);
});
test
(
'
Expand abbreviation with numbered repeaters with offset (HTML)
'
,
()
=>
{
return
testHtmlExpandAbbreviation
(
new
Selection
(
8
,
36
,
8
,
36
),
'
ul>li.item$@44*2
'
,
'
<ul>
\n\t\t\t
<li class="item44"></li>
\n\t\t\t
<li class="item45"></li>
\n\t\t
</ul>
'
);
});
test
(
'
Expand tag that is opened, but not closed (HTML)
'
,
()
=>
{
return
testHtmlExpandAbbreviation
(
new
Selection
(
9
,
6
,
9
,
6
),
'
<div
'
,
'
<div></div>
'
);
});
test
(
'
No expanding text inside open tag (HTML)
'
,
()
=>
{
return
testHtmlExpandAbbreviation
(
new
Selection
(
2
,
4
,
2
,
4
),
''
,
''
,
true
);
});
test
(
'
Expand css when inside style tag (HTML)
'
,
()
=>
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
13
,
3
,
13
,
6
);
let
expandPromise
=
expandAbbreviation
({
language
:
'
css
'
});
if
(
!
expandPromise
)
{
return
Promise
.
resolve
();
}
return
expandPromise
.
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
'
m10
'
,
'
margin: 10px;
'
));
return
Promise
.
resolve
();
});
});
});
});
suite
(
'
Tests for Expand Abbreviations (CSS)
'
,
()
=>
{
teardown
(
closeAllEditors
);
test
(
'
Expand abbreviation (CSS)
'
,
()
=>
{
return
withRandomFileEditor
(
cssContents
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
4
,
1
,
4
,
4
);
return
expandAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
cssContents
.
replace
(
'
m10
'
,
'
margin: 10px;
'
));
return
Promise
.
resolve
();
});
});
});
});
function
testHtmlExpandAbbreviation
(
selection
:
Selection
,
abbreviation
:
string
,
expandedText
:
string
,
shouldFail
?:
boolean
):
Thenable
<
any
>
{
return
withRandomFileEditor
(
htmlContents
,
'
html
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
selection
;
let
expandPromise
=
expandAbbreviation
(
null
);
if
(
!
expandPromise
)
{
if
(
!
shouldFail
)
{
assert
.
equal
(
1
,
2
,
`Problem with expanding
${
abbreviation
}
to
${
expandedText
}
`
);
}
return
Promise
.
resolve
();
}
return
expandPromise
.
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
htmlContents
.
replace
(
abbreviation
,
expandedText
));
return
Promise
.
resolve
();
});
});
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录