Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
6f3fb80d
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,体验更适合开发者的 AI 搜索 >>
提交
6f3fb80d
编写于
10月 22, 2020
作者:
M
meganrogge
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add basics for selecting header content without subheaders
上级
920a07f9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
25 addition
and
7 deletion
+25
-7
extensions/markdown-language-features/src/features/smartSelect.ts
...ns/markdown-language-features/src/features/smartSelect.ts
+25
-7
未找到文件。
extensions/markdown-language-features/src/features/smartSelect.ts
浏览文件 @
6f3fb80d
...
...
@@ -69,15 +69,18 @@ export default class MarkdownSmartSelect implements vscode.SelectionRangeProvide
return
undefined
;
}
let
parentRange
=
createHeaderRange
(
headers
.
shift
());
let
parentRange
=
createHeaderRange
(
headers
.
shift
()
,
undefined
,
headers
.
length
===
0
?
headerInfo
.
child
:
undefined
);
let
currentRange
:
vscode
.
SelectionRange
|
undefined
;
// get first child header below this
let
index
=
0
;
for
(
const
header
of
headers
)
{
if
(
parentRange
)
{
if
(
parentRange
.
range
.
contains
(
header
.
location
.
range
))
{
if
(
headerInfo
.
headerOnThisLine
&&
index
===
headers
.
length
-
1
)
{
// handle child header
currentRange
=
new
vscode
.
SelectionRange
(
header
.
location
.
range
,
parentRange
);
}
else
if
(
index
===
headers
.
length
-
1
)
{
currentRange
=
createHeaderRange
(
header
,
parentRange
,
headerInfo
.
child
);
}
else
{
currentRange
=
createHeaderRange
(
header
,
parentRange
);
}
...
...
@@ -107,13 +110,19 @@ function getTokensForPosition(tokens: Token[], position: vscode.Position): Token
return
sortedTokens
;
}
function
getHeadersForPosition
(
toc
:
TocEntry
[],
position
:
vscode
.
Position
):
{
headers
:
TocEntry
[],
headerOnThisLine
:
boolean
}
{
function
getHeadersForPosition
(
toc
:
TocEntry
[],
position
:
vscode
.
Position
):
{
headers
:
TocEntry
[],
headerOnThisLine
:
boolean
,
child
?:
vscode
.
Range
}
{
let
enclosingHeaders
=
toc
.
filter
(
header
=>
header
.
location
.
range
.
start
.
line
<=
position
.
line
&&
header
.
location
.
range
.
end
.
line
>=
position
.
line
);
let
sortedHeaders
=
enclosingHeaders
.
sort
((
header1
,
header2
)
=>
(
header1
.
line
-
position
.
line
)
-
(
header2
.
line
-
position
.
line
));
let
onThisLine
=
toc
.
find
(
header
=>
header
.
line
===
position
.
line
)
!==
undefined
;
let
filteredChildren
=
toc
.
filter
(
header
=>
header
.
line
>
position
.
line
).
sort
((
header1
,
header2
)
=>
(
header1
.
line
-
position
.
line
)
-
(
header2
.
line
-
position
.
line
));
let
child
:
vscode
.
Range
|
undefined
;
if
(
filteredChildren
.
length
>
0
)
{
child
=
filteredChildren
[
0
].
location
.
range
;
}
return
{
headers
:
sortedHeaders
,
headerOnThisLine
:
onThisLine
headerOnThisLine
:
onThisLine
,
child
:
child
};
}
...
...
@@ -121,14 +130,23 @@ function isBlockElement(token: Token): boolean {
return
!
[
'
list_item_close
'
,
'
paragraph_close
'
,
'
bullet_list_close
'
,
'
inline
'
,
'
heading_close
'
,
'
heading_open
'
].
includes
(
token
.
type
);
}
function
createHeaderRange
(
header
:
TocEntry
|
undefined
,
parent
?:
vscode
.
SelectionRange
):
vscode
.
SelectionRange
|
undefined
{
function
createHeaderRange
(
header
:
TocEntry
|
undefined
,
parent
?:
vscode
.
SelectionRange
,
child
?:
vscode
.
Range
|
undefined
):
vscode
.
SelectionRange
|
undefined
{
if
(
header
)
{
let
contentRange
=
new
vscode
.
Range
(
header
.
location
.
range
.
start
.
translate
(
1
),
header
.
location
.
range
.
end
);
let
headerPlusContentRange
=
header
.
location
.
range
;
let
partialContentRange
=
child
?
contentRange
.
with
(
undefined
,
child
.
start
.
translate
(
1
,
undefined
))
:
undefined
;
if
(
parent
&&
parent
.
range
.
contains
(
headerPlusContentRange
))
{
return
new
vscode
.
SelectionRange
(
contentRange
,
new
vscode
.
SelectionRange
(
headerPlusContentRange
,
parent
));
if
(
partialContentRange
)
{
return
new
vscode
.
SelectionRange
(
partialContentRange
,
new
vscode
.
SelectionRange
(
contentRange
,
(
new
vscode
.
SelectionRange
(
headerPlusContentRange
,
parent
))));
}
else
{
return
new
vscode
.
SelectionRange
(
contentRange
,
new
vscode
.
SelectionRange
(
headerPlusContentRange
,
parent
));
}
}
else
{
return
new
vscode
.
SelectionRange
(
contentRange
,
new
vscode
.
SelectionRange
(
headerPlusContentRange
));
if
(
partialContentRange
)
{
return
new
vscode
.
SelectionRange
(
partialContentRange
,
new
vscode
.
SelectionRange
(
contentRange
,
(
new
vscode
.
SelectionRange
(
headerPlusContentRange
))));
}
else
{
return
new
vscode
.
SelectionRange
(
contentRange
,
new
vscode
.
SelectionRange
(
headerPlusContentRange
));
}
}
}
else
{
return
undefined
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录