Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
2792b8f4
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2792b8f4
编写于
3月 26, 2018
作者:
R
Ramya Achutha Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Skip emmet inside comments in stylesheets when running the command
上级
4f10555e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
11 deletion
+37
-11
extensions/emmet/src/abbreviationActions.ts
extensions/emmet/src/abbreviationActions.ts
+9
-5
extensions/emmet/src/defaultCompletionProvider.ts
extensions/emmet/src/defaultCompletionProvider.ts
+4
-6
extensions/emmet/src/test/cssAbbreviationAction.test.ts
extensions/emmet/src/test/cssAbbreviationAction.test.ts
+24
-0
未找到文件。
extensions/emmet/src/abbreviationActions.ts
浏览文件 @
2792b8f4
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
{
Node
,
HtmlNode
,
Rule
,
Property
}
from
'
EmmetNode
'
;
import
{
Node
,
HtmlNode
,
Rule
,
Property
,
Stylesheet
}
from
'
EmmetNode
'
;
import
{
getEmmetHelper
,
getNode
,
getInnerRange
,
getMappingForIncludedLanguages
,
parseDocument
,
validate
,
getEmmetConfiguration
,
isStyleSheet
,
getEmmetMode
}
from
'
./util
'
;
const
trimRegex
=
/
[\u
00a0
]
*
[\d
|#|
\-
|
\*
|
\u
2022
]
+
\.?
/
;
...
...
@@ -290,8 +290,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
return
;
}
let
currentNode
=
getNode
(
rootNode
,
position
,
true
);
if
(
!
isValidLocationForEmmetAbbreviation
(
editor
.
document
,
currentNode
,
syntax
,
position
,
rangeToReplace
))
{
if
(
!
isValidLocationForEmmetAbbreviation
(
editor
.
document
,
rootNode
,
syntax
,
position
,
rangeToReplace
))
{
return
;
}
...
...
@@ -321,13 +320,18 @@ function fallbackTab(): Thenable<boolean | undefined> {
* Checks if given position is a valid location to expand emmet abbreviation.
* Works only on html and css/less/scss syntax
* @param document current Text Document
* @param
currentNode parsed node at given position
* @param
rootNode parsed document
* @param syntax syntax of the abbreviation
* @param position position to validate
* @param abbreviationRange The range of the abbreviation for which given position is being validated
*/
export
function
isValidLocationForEmmetAbbreviation
(
document
:
vscode
.
TextDocument
,
currentNode
:
Node
|
null
,
syntax
:
string
,
position
:
vscode
.
Position
,
abbreviationRange
:
vscode
.
Range
):
boolean
{
export
function
isValidLocationForEmmetAbbreviation
(
document
:
vscode
.
TextDocument
,
rootNode
:
Node
|
undefined
,
syntax
:
string
,
position
:
vscode
.
Position
,
abbreviationRange
:
vscode
.
Range
):
boolean
{
const
currentNode
=
rootNode
?
getNode
(
rootNode
,
position
,
true
)
:
null
;
if
(
isStyleSheet
(
syntax
))
{
const
stylesheet
=
<
Stylesheet
>
rootNode
;
if
(
stylesheet
&&
(
stylesheet
.
comments
||
[]).
some
(
x
=>
position
.
isAfterOrEqual
(
x
.
start
)
&&
position
.
isBeforeOrEqual
(
x
.
end
)))
{
return
false
;
}
// Continue validation only if the file was parse-able and the currentNode has been found
if
(
!
currentNode
)
{
return
true
;
...
...
extensions/emmet/src/defaultCompletionProvider.ts
浏览文件 @
2792b8f4
...
...
@@ -34,22 +34,20 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
}
let
validateLocation
=
false
;
let
currentNode
:
Node
|
null
=
null
;
let
rootNode
:
Stylesheet
|
undefined
=
undefined
;
if
(
context
.
triggerKind
!==
vscode
.
CompletionTriggerKind
.
TriggerForIncompleteCompletions
)
{
validateLocation
=
syntax
===
'
html
'
||
isStyleSheet
(
document
.
languageId
);
// If document can be css parsed, get currentNode
if
(
isStyleSheet
(
document
.
languageId
))
{
const
rootNode
=
document
.
lineCount
>
1000
?
parsePartialStylesheet
(
document
,
position
)
:
<
Stylesheet
>
parseDocument
(
document
,
false
);
if
(
!
rootNode
||
(
rootNode
.
comments
||
[]).
some
(
x
=>
position
.
isAfterOrEqual
(
x
.
start
)
&&
position
.
isBeforeOrEqual
(
x
.
end
))
)
{
rootNode
=
document
.
lineCount
>
1000
?
parsePartialStylesheet
(
document
,
position
)
:
<
Stylesheet
>
parseDocument
(
document
,
false
);
if
(
!
rootNode
)
{
return
;
}
currentNode
=
getNode
(
rootNode
,
position
,
true
);
}
}
if
(
validateLocation
&&
!
isValidLocationForEmmetAbbreviation
(
document
,
curren
tNode
,
syntax
,
position
,
extractAbbreviationResults
.
abbreviationRange
))
{
if
(
validateLocation
&&
!
isValidLocationForEmmetAbbreviation
(
document
,
roo
tNode
,
syntax
,
position
,
extractAbbreviationResults
.
abbreviationRange
))
{
return
;
}
...
...
extensions/emmet/src/test/cssAbbreviationAction.test.ts
浏览文件 @
2792b8f4
...
...
@@ -65,6 +65,30 @@ suite('Tests for Expand Abbreviations (CSS)', () => {
});
});
test
(
'
No emmet when cursor inside comment (CSS)
'
,
()
=>
{
const
testContent
=
`
.foo {
/*margin: 10px;
m10
padding: 10px;*/
display: auto;
}
`
;
return
withRandomFileEditor
(
testContent
,
'
css
'
,
(
editor
,
doc
)
=>
{
editor
.
selection
=
new
Selection
(
3
,
4
,
3
,
4
);
return
expandEmmetAbbreviation
(
null
).
then
(()
=>
{
assert
.
equal
(
editor
.
document
.
getText
(),
testContent
);
const
cancelSrc
=
new
CancellationTokenSource
();
const
completionPromise
=
completionProvider
.
provideCompletionItems
(
editor
.
document
,
new
Position
(
2
,
10
),
cancelSrc
.
token
,
{
triggerKind
:
CompletionTriggerKind
.
Invoke
});
if
(
completionPromise
)
{
assert
.
equal
(
1
,
2
,
`Invalid completion at property value`
);
}
return
Promise
.
resolve
();
});
});
});
test
(
'
No emmet when cursor in selector of a rule (CSS)
'
,
()
=>
{
const
testContent
=
`
.foo {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录