Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
283a790c
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,发现更多精彩内容 >>
提交
283a790c
编写于
7月 24, 2017
作者:
R
Ramya Achutha Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Emmet: Reflect CSS Value in extension #31298
上级
83289390
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
87 addition
and
17 deletion
+87
-17
extensions/emmet/src/extension.ts
extensions/emmet/src/extension.ts
+6
-0
extensions/emmet/src/reflectCssValue.ts
extensions/emmet/src/reflectCssValue.ts
+61
-0
extensions/emmet/src/typings/EmmetNode.d.ts
extensions/emmet/src/typings/EmmetNode.d.ts
+2
-0
extensions/emmet/src/updateImageSize.ts
extensions/emmet/src/updateImageSize.ts
+7
-16
extensions/emmet/src/util.ts
extensions/emmet/src/util.ts
+11
-1
未找到文件。
extensions/emmet/src/extension.ts
浏览文件 @
283a790c
...
...
@@ -20,6 +20,8 @@ import { incrementDecrement } from './incrementDecrement';
import
{
LANGUAGE_MODES
,
getMappingForIncludedLanguages
}
from
'
./util
'
;
import
{
updateExtensionsPath
}
from
'
vscode-emmet-helper
'
;
import
{
updateImageSize
}
from
'
./updateImageSize
'
;
import
{
reflectCssValue
}
from
'
./reflectCssValue
'
;
import
*
as
path
from
'
path
'
;
export
function
activate
(
context
:
vscode
.
ExtensionContext
)
{
...
...
@@ -118,6 +120,10 @@ export function activate(context: vscode.ExtensionContext) {
return
updateImageSize
();
}));
context
.
subscriptions
.
push
(
vscode
.
commands
.
registerCommand
(
'
emmet.reflectCssValue
'
,
()
=>
{
return
reflectCssValue
();
}));
let
currentExtensionsPath
=
undefined
;
let
resolveUpdateExtensionsPath
=
()
=>
{
let
extensionsPath
=
vscode
.
workspace
.
getConfiguration
(
'
emmet
'
)[
'
extensionsPath
'
];
...
...
extensions/emmet/src/reflectCssValue.ts
0 → 100644
浏览文件 @
283a790c
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
Range
,
window
,
TextEditor
}
from
'
vscode
'
;
import
{
isStyleSheet
}
from
'
vscode-emmet-helper
'
;
import
{
parse
,
getNode
,
getCssProperty
}
from
'
./util
'
;
import
{
Property
,
Rule
}
from
'
EmmetNode
'
;
const
vendorPrefixes
=
[
'
-webkit-
'
,
'
-moz-
'
,
'
-ms-
'
,
'
-o-
'
,
''
];
export
function
reflectCssValue
()
{
let
editor
=
window
.
activeTextEditor
;
if
(
!
editor
)
{
window
.
showInformationMessage
(
'
No editor is active.
'
);
return
;
}
if
(
!
isStyleSheet
(
editor
.
document
.
languageId
))
{
return
;
}
const
rootNode
=
parse
(
editor
.
document
);
const
node
=
getNode
(
rootNode
,
editor
.
selection
.
active
,
true
);
if
(
!
node
||
node
.
type
!==
'
property
'
)
{
return
;
}
return
updateCSSNode
(
editor
,
<
Property
>
node
);
}
function
updateCSSNode
(
editor
:
TextEditor
,
property
:
Property
)
{
const
rule
:
Rule
=
property
.
parent
;
let
currentPrefix
=
''
;
// Find vendor prefix of given property node
for
(
let
i
=
0
;
i
<
vendorPrefixes
.
length
;
i
++
)
{
if
(
property
.
name
.
startsWith
(
vendorPrefixes
[
i
]))
{
currentPrefix
=
vendorPrefixes
[
i
];
break
;
}
}
const
propertyName
=
property
.
name
.
substr
(
currentPrefix
.
length
);
const
propertyValue
=
property
.
value
;
return
editor
.
edit
(
builder
=>
{
// Find properties with vendor prefixes, update each
vendorPrefixes
.
forEach
(
prefix
=>
{
if
(
prefix
===
currentPrefix
)
{
return
;
}
let
vendorProperty
=
getCssProperty
(
rule
,
prefix
+
propertyName
);
if
(
vendorProperty
)
{
builder
.
replace
(
new
Range
(
vendorProperty
.
valueToken
.
start
,
vendorProperty
.
valueToken
.
end
),
propertyValue
);
}
});
});
}
\ No newline at end of file
extensions/emmet/src/typings/EmmetNode.d.ts
浏览文件 @
283a790c
...
...
@@ -52,6 +52,7 @@ declare module 'EmmetNode' {
}
export
interface
CssNode
extends
Node
{
name
:
string
parent
:
CssNode
firstChild
:
CssNode
nextSibling
:
CssNode
...
...
@@ -70,6 +71,7 @@ declare module 'EmmetNode' {
separator
:
Token
parent
:
Rule
terminatorToken
:
Token
value
:
string
}
export
interface
Stylesheet
extends
Node
{
...
...
extensions/emmet/src/updateImageSize.ts
浏览文件 @
283a790c
...
...
@@ -11,7 +11,7 @@ import { TextEditor, Range, Position, window } from 'vscode';
import
*
as
path
from
'
path
'
;
import
{
getImageSize
}
from
'
./imageSizeHelper
'
;
import
{
isStyleSheet
}
from
'
vscode-emmet-helper
'
;
import
{
parse
,
getNode
,
iterateCSSToken
}
from
'
./util
'
;
import
{
parse
,
getNode
,
iterateCSSToken
,
getCssProperty
}
from
'
./util
'
;
import
{
HtmlNode
,
CssToken
,
HtmlToken
,
Attribute
,
Property
}
from
'
EmmetNode
'
;
import
{
locateFile
}
from
'
./locateFile
'
;
import
parseStylesheet
from
'
@emmetio/css-parser
'
;
...
...
@@ -213,12 +213,12 @@ function updateHTMLTag(editor: TextEditor, node: HtmlNode, width: number, height
*/
function
updateCSSNode
(
editor
:
TextEditor
,
srcProp
:
Property
,
width
:
number
,
height
:
number
)
{
const
rule
=
srcProp
.
parent
;
const
widthProp
=
getProperty
(
rule
,
'
width
'
);
const
heightProp
=
getProperty
(
rule
,
'
height
'
);
const
widthProp
=
get
Css
Property
(
rule
,
'
width
'
);
const
heightProp
=
get
Css
Property
(
rule
,
'
height
'
);
// Detect formatting
const
separator
=
srcProp
.
separator
||
'
:
'
;
const
before
=
get
Before
(
editor
,
srcProp
);
const
before
=
get
PropertyDelimitor
(
editor
,
srcProp
);
let
edits
:
[
Range
,
string
][]
=
[];
if
(
!
srcProp
.
terminatorToken
)
{
...
...
@@ -291,23 +291,13 @@ function findUrlToken(node, pos: Position) {
}
}
/**
* Returns `name` CSS property from given `rule`
* @param {Node} rule
* @param {String} name
* @return {Node}
*/
function
getProperty
(
rule
,
name
)
{
return
rule
.
children
.
find
(
node
=>
node
.
type
===
'
property
'
&&
node
.
name
===
name
);
}
/**
* Returns a string that is used to delimit properties in current node’s rule
* @param {TextEditor} editor
* @param {
Node
} node
* @param {
Property
} node
* @return {String}
*/
function
get
Before
(
editor
:
TextEditor
,
node
:
Property
)
{
function
get
PropertyDelimitor
(
editor
:
TextEditor
,
node
:
Property
)
{
let
anchor
;
if
(
anchor
=
(
node
.
previousSibling
||
node
.
parent
.
contentStartToken
))
{
return
editor
.
document
.
getText
(
new
Range
(
anchor
.
end
,
node
.
start
));
...
...
@@ -317,3 +307,4 @@ function getBefore(editor: TextEditor, node: Property) {
return
''
;
}
extensions/emmet/src/util.ts
浏览文件 @
283a790c
...
...
@@ -6,7 +6,7 @@
import
*
as
vscode
from
'
vscode
'
;
import
parse
from
'
@emmetio/html-matcher
'
;
import
parseStylesheet
from
'
@emmetio/css-parser
'
;
import
{
Node
,
HtmlNode
,
CssToken
}
from
'
EmmetNode
'
;
import
{
Node
,
HtmlNode
,
CssToken
,
Property
}
from
'
EmmetNode
'
;
import
{
DocumentStreamReader
}
from
'
./bufferStream
'
;
import
{
isStyleSheet
}
from
'
vscode-emmet-helper
'
;
...
...
@@ -276,3 +276,13 @@ export function iterateCSSToken(token: CssToken, fn) {
}
}
}
/**
* Returns `name` CSS property from given `rule`
* @param {Node} rule
* @param {String} name
* @return {Property}
*/
export
function
getCssProperty
(
rule
,
name
):
Property
{
return
rule
.
children
.
find
(
node
=>
node
.
type
===
'
property
'
&&
node
.
name
===
name
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录