Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
56eebb2b
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,发现更多精彩内容 >>
提交
56eebb2b
编写于
7月 23, 2017
作者:
R
Ramya Achutha Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Emmet Update ImageSize inside style tag
上级
0bee43b5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
5 deletion
+31
-5
extensions/emmet/src/updateImageSize.ts
extensions/emmet/src/updateImageSize.ts
+31
-5
未找到文件。
extensions/emmet/src/updateImageSize.ts
浏览文件 @
56eebb2b
...
...
@@ -14,6 +14,8 @@ import { isStyleSheet } from 'vscode-emmet-helper';
import
{
parse
,
getNode
,
iterateCSSToken
}
from
'
./util
'
;
import
{
HtmlNode
,
CssToken
,
HtmlToken
,
Attribute
,
Property
}
from
'
EmmetNode
'
;
import
{
locateFile
}
from
'
./locateFile
'
;
import
parseStylesheet
from
'
@emmetio/css-parser
'
;
import
{
DocumentStreamReader
}
from
'
./bufferStream
'
;
/**
* Updates size of context image in given editor
...
...
@@ -28,7 +30,7 @@ export function updateImageSize() {
if
(
!
isStyleSheet
(
editor
.
document
.
languageId
))
{
return
updateImageSizeHTML
(
editor
);
}
else
{
return
updateImageSizeCSS
(
editor
);
return
updateImageSizeCSS
File
(
editor
);
}
}
...
...
@@ -39,7 +41,7 @@ function updateImageSizeHTML(editor: TextEditor) {
const
src
=
getImageSrcHTML
(
getImageHTMLNode
(
editor
));
if
(
!
src
)
{
return
Promise
.
reject
(
new
Error
(
'
No valid image source
'
)
);
return
updateImageSizeStyleTag
(
editor
);
}
locateFile
(
path
.
dirname
(
editor
.
document
.
fileName
),
src
)
...
...
@@ -55,12 +57,33 @@ function updateImageSizeHTML(editor: TextEditor) {
.
catch
(
err
=>
console
.
warn
(
'
Error while updating image size:
'
,
err
));
}
function
updateImageSizeStyleTag
(
editor
:
TextEditor
)
{
let
getPropertyInsiderStyleTag
=
(
editor
)
=>
{
const
rootNode
=
parse
(
editor
.
document
);
const
currentNode
=
<
HtmlNode
>
getNode
(
rootNode
,
editor
.
selection
.
active
);
if
(
currentNode
&&
currentNode
.
name
===
'
style
'
&&
currentNode
.
open
.
end
.
isBefore
(
editor
.
selection
.
active
)
&&
currentNode
.
close
.
start
.
isAfter
(
editor
.
selection
.
active
))
{
let
buffer
=
new
DocumentStreamReader
(
editor
.
document
,
currentNode
.
start
,
new
Range
(
currentNode
.
start
,
currentNode
.
end
));
let
rootNode
=
parseStylesheet
(
buffer
);
const
node
=
getNode
(
rootNode
,
editor
.
selection
.
active
);
return
(
node
&&
node
.
type
===
'
property
'
)
?
<
Property
>
node
:
null
;
}
};
return
updateImageSizeCSS
(
editor
,
getPropertyInsiderStyleTag
);
}
function
updateImageSizeCSSFile
(
editor
:
TextEditor
)
{
return
updateImageSizeCSS
(
editor
,
getImageCSSNode
);
}
/**
* Updates image size of context rule of stylesheet model
*/
function
updateImageSizeCSS
(
editor
:
TextEditor
)
{
function
updateImageSizeCSS
(
editor
:
TextEditor
,
fetchNode
:
(
editor
)
=>
Property
)
{
const
src
=
getImageSrcCSS
(
getImageCSS
Node
(
editor
),
editor
.
selection
.
active
);
const
src
=
getImageSrcCSS
(
fetch
Node
(
editor
),
editor
.
selection
.
active
);
if
(
!
src
)
{
return
Promise
.
reject
(
new
Error
(
'
No valid image source
'
));
...
...
@@ -71,7 +94,7 @@ function updateImageSizeCSS(editor: TextEditor) {
.
then
((
size
:
any
)
=>
{
// since this action is asynchronous, we have to ensure that editor wasn’t
// changed and user didn’t moved caret outside <img> node
const
prop
=
getImageCSS
Node
(
editor
);
const
prop
=
fetch
Node
(
editor
);
if
(
getImageSrcCSS
(
prop
,
editor
.
selection
.
active
)
===
src
)
{
updateCSSNode
(
editor
,
prop
,
size
.
width
,
size
.
height
);
}
...
...
@@ -126,6 +149,9 @@ function getImageSrcHTML(node: HtmlNode): string {
* @return {string}
*/
function
getImageSrcCSS
(
node
:
Property
,
position
:
Position
):
string
{
if
(
!
node
)
{
return
;
}
const
urlToken
=
findUrlToken
(
node
,
position
);
if
(
!
urlToken
)
{
return
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录