Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
fd33dfa5
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 搜索 >>
提交
fd33dfa5
编写于
10月 16, 2020
作者:
M
meganrogge
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
back to working
上级
9cc523a6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
39 deletion
+35
-39
extensions/markdown-language-features/src/features/smartSelect.ts
...ns/markdown-language-features/src/features/smartSelect.ts
+35
-39
未找到文件。
extensions/markdown-language-features/src/features/smartSelect.ts
浏览文件 @
fd33dfa5
...
...
@@ -12,59 +12,47 @@ export default class MarkdownSmartSelect implements vscode.SelectionRangeProvide
constructor
(
private
readonly
engine
:
MarkdownEngine
)
{
}
public
async
provideSelectionRanges
(
document
:
vscode
.
TextDocument
,
positions
:
vscode
.
Position
[],
_token
:
vscode
.
CancellationToken
):
Promise
<
vscode
.
SelectionRange
[]
>
{
let
rangesForPositions
:
vscode
.
SelectionRange
[]
=
[];
positions
.
forEach
(
async
(
position
)
=>
{
public
async
provideSelectionRanges
(
document
:
vscode
.
TextDocument
,
positions
:
vscode
.
Position
[],
_token
:
vscode
.
CancellationToken
):
Promise
<
vscode
.
SelectionRange
[]
>
{
return
await
Promise
.
all
(
positions
.
map
(
async
(
position
)
=>
{
return
await
this
.
provideSelectionRange
(
document
,
position
,
_token
);
}));
}
let
ranges
:
vscode
.
SelectionRange
[]
=
await
Promise
.
all
([
private
async
provideSelectionRange
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
,
_token
:
vscode
.
CancellationToken
):
Promise
<
vscode
.
SelectionRange
>
{
let
ranges
:
(
vscode
.
SelectionRange
|
undefined
)
[]
=
await
Promise
.
all
([
await
this
.
getHeaderSelectionRanges
(
document
,
position
),
await
this
.
getBlockSelectionRanges
(
document
,
position
)
]);
let
result
:
vscode
.
SelectionRange
[]
=
ranges
.
filter
(
range
=>
range
);
let
result
:
(
vscode
.
SelectionRange
)
[]
=
ranges
.
filter
(
range
=>
range
!==
undefined
)
as
vscode
.
SelectionRange
[];
if
(
result
.
length
===
2
)
{
// need to combine them to return only smallest child range
let
parent
=
result
[
0
];
let
child
=
result
[
1
];
let
childParent
=
child
.
parent
;
if
(
childParent
)
{
if
(
parent
.
range
.
contains
(
childParent
.
range
))
{
let
revisedParent
=
new
vscode
.
SelectionRange
(
childParent
.
range
,
parent
);
if
(
revisedParent
.
range
.
contains
(
child
.
range
))
{
rangesForPositions
.
push
(
new
vscode
.
SelectionRange
(
child
.
range
,
revisedParent
));
let
header
=
result
[
0
];
let
block
=
result
[
1
];
let
blockParent
=
block
.
parent
;
if
(
blockParent
)
{
if
(
header
.
range
.
contains
(
blockParent
.
range
))
{
let
revisedParent
=
new
vscode
.
SelectionRange
(
blockParent
.
range
,
header
);
if
(
revisedParent
.
range
.
contains
(
block
.
range
))
{
return
new
vscode
.
SelectionRange
(
block
.
range
,
revisedParent
);
}
}
else
{
// they're one line off
let
overlap
=
childParent
.
range
.
union
(
parent
.
range
);
if
(
overlap
)
{
parent
.
range
=
overlap
;
}
if
(
parent
.
range
.
contains
(
childParent
.
range
))
{
childParent
.
parent
=
parent
;
rangesForPositions
.
push
(
new
vscode
.
SelectionRange
(
child
.
range
,
childParent
));
if
(
header
.
range
.
contains
(
block
.
range
))
{
return
new
vscode
.
SelectionRange
(
block
.
range
,
header
);
}
}
}
else
{
if
(
parent
.
range
.
contains
(
child
.
range
))
{
r
angesForPositions
.
push
(
new
vscode
.
SelectionRange
(
child
.
range
,
parent
)
);
if
(
header
.
range
.
contains
(
block
.
range
))
{
r
eturn
new
vscode
.
SelectionRange
(
block
.
range
,
header
);
}
}
r
angesForPositions
.
push
(
child
)
;
r
eturn
block
;
}
else
{
r
angesForPositions
.
push
(
result
[
0
])
;
r
eturn
result
[
0
]
;
}
});
if
(
rangesForPositions
)
{
// stop here
}
return
rangesForPositions
;
}
private
async
getBlockSelectionRanges
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
):
Promise
<
vscode
.
SelectionRange
>
{
private
async
getBlockSelectionRanges
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
):
Promise
<
vscode
.
SelectionRange
|
undefined
>
{
const
tokens
=
await
this
.
engine
.
parse
(
document
);
...
...
@@ -73,6 +61,10 @@ export default class MarkdownSmartSelect implements vscode.SelectionRangeProvide
// sort from smallest to largest line range
let
sortedTokens
=
nearbyTokens
.
sort
((
tokenOne
,
tokenTwo
)
=>
(
tokenTwo
.
map
[
1
]
-
tokenTwo
.
map
[
0
]
-
tokenOne
.
map
[
1
]
-
tokenOne
.
map
[
0
]));
if
(
sortedTokens
.
length
===
0
)
{
return
undefined
;
}
let
parentToken
=
sortedTokens
.
pop
();
if
(
parentToken
)
{
...
...
@@ -80,8 +72,7 @@ export default class MarkdownSmartSelect implements vscode.SelectionRangeProvide
let
parentRange
=
new
vscode
.
SelectionRange
(
new
vscode
.
Range
(
new
vscode
.
Position
(
parentToken
.
map
[
0
]
>
0
?
parentToken
.
map
[
0
]
-
1
:
0
,
0
),
new
vscode
.
Position
(
parentToken
.
map
[
1
],
0
)));
let
childRange
=
new
vscode
.
Range
(
new
vscode
.
Position
(
parentToken
.
map
[
0
]
+
1
,
0
),
new
vscode
.
Position
(
parentToken
.
map
[
1
]
-
1
,
0
));
if
(
parentRange
.
range
.
contains
(
childRange
))
{
let
child
=
new
vscode
.
SelectionRange
(
childRange
,
parentRange
);
return
child
;
return
new
vscode
.
SelectionRange
(
childRange
,
parentRange
);
}
}
else
{
let
parentRange
=
new
vscode
.
SelectionRange
(
new
vscode
.
Range
(
new
vscode
.
Position
(
parentToken
.
map
[
0
],
0
),
new
vscode
.
Position
(
parentToken
.
map
[
1
],
0
)));
...
...
@@ -101,7 +92,7 @@ export default class MarkdownSmartSelect implements vscode.SelectionRangeProvide
}
}
private
async
getHeaderSelectionRanges
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
):
Promise
<
vscode
.
SelectionRange
>
{
private
async
getHeaderSelectionRanges
(
document
:
vscode
.
TextDocument
,
position
:
vscode
.
Position
):
Promise
<
vscode
.
SelectionRange
|
undefined
>
{
const
tocProvider
=
new
TableOfContentsProvider
(
this
.
engine
,
document
);
const
toc
=
await
tocProvider
.
getToc
();
...
...
@@ -110,6 +101,10 @@ export default class MarkdownSmartSelect implements vscode.SelectionRangeProvide
let
nearbyHeaders
=
toc
.
filter
(
header
=>
header
.
location
.
range
.
start
.
line
<=
position
.
line
&&
header
.
location
.
range
.
end
.
line
>=
position
.
line
);
let
sortedHeaders
=
nearbyHeaders
.
sort
((
header1
,
header2
)
=>
(
header1
.
line
-
position
.
line
)
-
(
header2
.
line
-
position
.
line
));
if
(
sortedHeaders
.
length
===
0
)
{
return
undefined
;
}
let
parentHeader
=
sortedHeaders
.
shift
();
let
parentRange
:
vscode
.
SelectionRange
;
let
currentRange
:
vscode
.
SelectionRange
;
...
...
@@ -121,6 +116,7 @@ export default class MarkdownSmartSelect implements vscode.SelectionRangeProvide
parentRange
=
new
vscode
.
SelectionRange
(
contentRange
,
headerPlusContent
);
}
}
let
index
=
0
;
sortedHeaders
.
forEach
(
header
=>
{
if
(
parentHeader
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录