Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
0da90fcc
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,发现更多精彩内容 >>
提交
0da90fcc
编写于
6月 06, 2017
作者:
R
Ramya Achutha Rao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
toggle comment across html nodes #27629
上级
a5c9a7c5
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
71 addition
and
10 deletion
+71
-10
extensions/emmet/src/toggleComment.ts
extensions/emmet/src/toggleComment.ts
+20
-10
extensions/emmet/src/util.ts
extensions/emmet/src/util.ts
+51
-0
未找到文件。
extensions/emmet/src/toggleComment.ts
浏览文件 @
0da90fcc
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
{
getNode
,
isStyleSheet
}
from
'
./util
'
;
import
{
getNode
,
isStyleSheet
,
getNodesInBetween
}
from
'
./util
'
;
import
parse
from
'
@emmetio/html-matcher
'
;
import
parseStylesheet
from
'
@emmetio/css-parser
'
;
import
Node
from
'
@emmetio/node
'
;
...
...
@@ -58,19 +58,29 @@ export function toggleComment() {
}
function
toggleCommentHTML
(
document
:
vscode
.
TextDocument
,
selection
:
vscode
.
Selection
,
rootNode
:
Node
):
[
vscode
.
Range
[],
vscode
.
Position
,
vscode
.
Position
]
{
let
offset
=
document
.
offsetAt
(
selection
.
start
);
let
nodeToUpdate
=
getNode
(
rootNode
,
offset
);
if
(
!
nodeToUpdate
)
{
const
selectionStart
=
document
.
offsetAt
(
selection
.
isReversed
?
selection
.
active
:
selection
.
anchor
);
const
selectionEnd
=
document
.
offsetAt
(
selection
.
isReversed
?
selection
.
anchor
:
selection
.
active
);
let
startNode
=
getNode
(
rootNode
,
selectionStart
,
true
);
let
endNode
=
getNode
(
rootNode
,
selectionEnd
,
true
);
if
(
!
startNode
||
!
endNode
)
{
return
[[],
null
,
null
];
}
let
rangesToUnComment
=
getRangesToUnCommentHTML
(
nodeToUpdate
,
document
);
if
(
nodeToUpdate
.
type
===
'
comment
'
)
{
let
allNodes
:
Node
[]
=
getNodesInBetween
(
startNode
,
endNode
);
let
rangesToUnComment
:
vscode
.
Range
[]
=
[];
allNodes
.
forEach
(
node
=>
{
rangesToUnComment
=
rangesToUnComment
.
concat
(
getRangesToUnCommentHTML
(
node
,
document
));
});
if
(
startNode
.
type
===
'
comment
'
)
{
return
[
rangesToUnComment
,
null
,
null
];
}
let
positionForCommentStart
=
document
.
positionAt
(
nodeToUpdate
.
start
);
let
positionForCommentEnd
=
document
.
positionAt
(
nodeToUpdate
.
end
);
let
positionForCommentStart
=
document
.
positionAt
(
allNodes
[
0
]
.
start
);
let
positionForCommentEnd
=
document
.
positionAt
(
allNodes
[
allNodes
.
length
-
1
]
.
end
);
return
[
rangesToUnComment
,
positionForCommentStart
,
positionForCommentEnd
];
}
...
...
@@ -95,8 +105,8 @@ function getRangesToUnCommentHTML(node: Node, document: vscode.TextDocument): vs
function
toggleCommentStylesheet
(
document
:
vscode
.
TextDocument
,
selection
:
vscode
.
Selection
,
rootNode
:
Node
):
[
vscode
.
Range
[],
vscode
.
Position
,
vscode
.
Position
]
{
let
selectionStart
=
document
.
offsetAt
(
selection
.
anchor
);
let
selectionEnd
=
document
.
offsetAt
(
selection
.
active
);
const
selectionStart
=
document
.
offsetAt
(
selection
.
isReversed
?
selection
.
active
:
selection
.
anchor
);
const
selectionEnd
=
document
.
offsetAt
(
selection
.
isReversed
?
selection
.
anchor
:
selection
.
active
);
// If current node is commented, then uncomment and return
let
rangesToUnComment
=
getRangesToUnCommentStylesheet
(
rootNode
,
selectionStart
,
selectionEnd
,
document
,
true
);
...
...
extensions/emmet/src/util.ts
浏览文件 @
0da90fcc
...
...
@@ -216,3 +216,54 @@ export function findPrevWord(propertyValue: string, pos: number): [number, numbe
return
[
newSelectionStart
,
newSelectionEnd
];
}
export
function
getNodesInBetween
(
node1
:
Node
,
node2
:
Node
):
Node
[]
{
// Same node
if
(
sameNodes
(
node1
,
node2
))
{
return
[
node1
];
}
// Same parent
if
(
sameNodes
(
node1
.
parent
,
node2
.
parent
))
{
return
getNextSiblingsTillPosition
(
node1
,
node2
.
end
);
}
// node2 is ancestor of node1
if
(
node2
.
start
<
node1
.
start
)
{
return
[
node2
];
}
// node1 is ancestor of node2
if
(
node2
.
start
<
node1
.
end
)
{
return
[
node1
];
}
// Get the highest ancestor of node1 that should be commented
while
(
node1
.
parent
&&
node1
.
parent
.
end
<
node2
.
start
)
{
node1
=
node1
.
parent
;
}
// Get the highest ancestor of node2 that should be commented
while
(
node2
.
parent
&&
node2
.
parent
.
start
>
node1
.
start
)
{
node2
=
node2
.
parent
;
}
return
getNextSiblingsTillPosition
(
node1
,
node2
.
end
);
}
function
getNextSiblingsTillPosition
(
node
:
Node
,
position
:
number
):
Node
[]
{
let
siblings
:
Node
[]
=
[];
let
currentNode
=
node
;
while
(
currentNode
&&
currentNode
.
start
<
position
)
{
siblings
.
push
(
currentNode
);
currentNode
=
currentNode
.
nextSibling
;
}
return
siblings
;
}
export
function
sameNodes
(
node1
:
Node
,
node2
:
Node
):
boolean
{
if
(
!
node1
||
!
node2
)
{
return
false
;
}
return
node1
.
start
===
node2
.
start
&&
node1
.
end
===
node2
.
end
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录