Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
6e2aa0bf
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,发现更多精彩内容 >>
提交
6e2aa0bf
编写于
11月 06, 2020
作者:
M
meganrogge
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean up code and remove unused methods
上级
ce7e6d99
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
64 deletion
+10
-64
extensions/markdown-language-features/src/features/smartSelect.ts
...ns/markdown-language-features/src/features/smartSelect.ts
+9
-63
extensions/markdown-language-features/src/test/smartSelect.test.ts
...s/markdown-language-features/src/test/smartSelect.test.ts
+1
-1
未找到文件。
extensions/markdown-language-features/src/features/smartSelect.ts
浏览文件 @
6e2aa0bf
...
...
@@ -112,34 +112,11 @@ function createBlockRange(block: Token, document: vscode.TextDocument, cursorLin
}
else
if
(
isList
(
block
)
&&
document
.
lineAt
(
endLine
).
isEmptyOrWhitespace
)
{
endLine
=
endLine
-
1
;
}
const
startPos
=
new
vscode
.
Position
(
startLine
,
0
);
const
endPos
=
new
vscode
.
Position
(
endLine
,
document
.
lineAt
(
endLine
).
text
?.
length
??
0
);
const
range
=
new
vscode
.
Range
(
startPos
,
endPos
);
if
(
parent
&&
parent
.
range
.
contains
(
range
)
&&
!
parent
.
range
.
isEqual
(
range
))
{
const
range
=
new
vscode
.
Range
(
startLine
,
0
,
endLine
,
document
.
lineAt
(
endLine
).
text
?.
length
??
0
);
if
(
parent
?.
range
.
contains
(
range
)
&&
!
parent
.
range
.
isEqual
(
range
))
{
return
new
vscode
.
SelectionRange
(
range
,
parent
);
}
else
if
(
parent
?.
range
.
isEqual
(
range
))
{
return
parent
;
}
else
if
(
parent
)
{
// parent doesn't contain range
if
(
rangeLinesEqual
(
range
,
parent
.
range
))
{
return
range
.
end
.
character
>
parent
.
range
.
end
.
character
?
new
vscode
.
SelectionRange
(
range
)
:
parent
;
}
else
if
(
parent
.
range
.
end
.
line
+
1
===
range
.
end
.
line
)
{
const
adjustedRange
=
new
vscode
.
Range
(
range
.
start
,
range
.
end
.
translate
(
-
1
,
parent
.
range
.
end
.
character
));
if
(
adjustedRange
.
isEqual
(
parent
.
range
))
{
return
parent
;
}
else
{
return
new
vscode
.
SelectionRange
(
adjustedRange
,
parent
);
}
}
else
if
(
parent
.
range
.
end
.
line
===
range
.
end
.
line
)
{
const
adjustedRange
=
new
vscode
.
Range
(
parent
.
range
.
start
,
range
.
end
.
translate
(
undefined
,
range
.
end
.
character
));
if
(
adjustedRange
.
isEqual
(
parent
.
range
))
{
return
parent
;
}
else
{
return
new
vscode
.
SelectionRange
(
adjustedRange
,
parent
.
parent
);
}
}
else
{
return
parent
;
}
}
else
{
return
new
vscode
.
SelectionRange
(
range
);
}
...
...
@@ -150,36 +127,17 @@ function createFencedRange(token: Token, cursorLine: number, document: vscode.Te
const
startLine
=
token
.
map
[
0
];
const
endLine
=
token
.
map
[
1
]
-
1
;
const
onFenceLine
=
cursorLine
===
startLine
||
cursorLine
===
endLine
;
const
fenceRange
=
new
vscode
.
Range
(
new
vscode
.
Position
(
startLine
,
0
),
new
vscode
.
Position
(
endLine
,
document
.
lineAt
(
endLine
).
text
.
length
));
const
contentRange
=
endLine
-
startLine
>
2
&&
!
onFenceLine
?
new
vscode
.
Range
(
new
vscode
.
Position
(
startLine
+
1
,
0
),
new
vscode
.
Position
(
endLine
-
1
,
document
.
lineAt
(
endLine
-
1
).
text
.
length
))
:
undefined
;
if
(
parent
&&
contentRange
)
{
if
(
parent
.
range
.
contains
(
fenceRange
)
&&
!
parent
.
range
.
isEqual
(
fenceRange
))
{
return
new
vscode
.
SelectionRange
(
contentRange
,
new
vscode
.
SelectionRange
(
fenceRange
,
parent
));
}
else
if
(
parent
.
range
.
isEqual
(
fenceRange
))
{
return
new
vscode
.
SelectionRange
(
contentRange
,
parent
);
}
else
if
(
rangeLinesEqual
(
fenceRange
,
parent
.
range
))
{
const
revisedRange
=
fenceRange
.
end
.
character
>
parent
.
range
.
end
.
character
?
fenceRange
:
parent
.
range
;
return
new
vscode
.
SelectionRange
(
contentRange
,
new
vscode
.
SelectionRange
(
revisedRange
,
getRealParent
(
parent
,
revisedRange
)));
}
else
if
(
parent
.
range
.
end
.
line
===
fenceRange
.
end
.
line
)
{
parent
.
range
.
end
.
translate
(
undefined
,
fenceRange
.
end
.
character
);
return
new
vscode
.
SelectionRange
(
contentRange
,
new
vscode
.
SelectionRange
(
fenceRange
,
parent
));
}
}
else
if
(
contentRange
)
{
return
new
vscode
.
SelectionRange
(
contentRange
,
new
vscode
.
SelectionRange
(
fenceRange
));
}
else
if
(
parent
)
{
if
(
parent
.
range
.
contains
(
fenceRange
)
&&
!
parent
.
range
.
isEqual
(
fenceRange
))
{
return
new
vscode
.
SelectionRange
(
fenceRange
,
parent
);
}
else
if
(
parent
.
range
.
isEqual
(
fenceRange
))
{
const
fenceRange
=
new
vscode
.
Range
(
startLine
,
0
,
endLine
,
document
.
lineAt
(
endLine
).
text
.
length
);
const
contentRange
=
endLine
-
startLine
>
2
&&
!
onFenceLine
?
new
vscode
.
Range
(
startLine
+
1
,
0
,
endLine
-
1
,
document
.
lineAt
(
endLine
-
1
).
text
.
length
)
:
undefined
;
if
(
contentRange
)
{
return
new
vscode
.
SelectionRange
(
contentRange
,
new
vscode
.
SelectionRange
(
fenceRange
,
parent
));
}
else
{
if
(
parent
?.
range
.
isEqual
(
fenceRange
))
{
return
parent
;
}
else
if
(
rangeLinesEqual
(
fenceRange
,
parent
.
range
))
{
const
revisedRange
=
fenceRange
.
end
.
character
>
parent
.
range
.
end
.
character
?
fenceRange
:
parent
.
range
;
return
new
vscode
.
SelectionRange
(
revisedRange
,
parent
.
parent
);
}
else
if
(
parent
.
range
.
end
.
line
===
fenceRange
.
end
.
line
)
{
parent
.
range
.
end
.
translate
(
undefined
,
fenceRange
.
end
.
character
);
}
else
{
return
new
vscode
.
SelectionRange
(
fenceRange
,
parent
);
}
}
return
new
vscode
.
SelectionRange
(
fenceRange
,
parent
);
}
function
isList
(
token
:
Token
):
boolean
{
...
...
@@ -190,14 +148,6 @@ function isBlockElement(token: Token): boolean {
return
!
[
'
list_item_close
'
,
'
paragraph_close
'
,
'
bullet_list_close
'
,
'
inline
'
,
'
heading_close
'
,
'
heading_open
'
].
includes
(
token
.
type
);
}
function
getRealParent
(
parent
:
vscode
.
SelectionRange
,
range
:
vscode
.
Range
)
{
let
currentParent
:
vscode
.
SelectionRange
|
undefined
=
parent
;
while
(
currentParent
&&
!
currentParent
.
range
.
contains
(
range
))
{
currentParent
=
currentParent
.
parent
;
}
return
currentParent
;
}
function
getFirstChildHeader
(
document
:
vscode
.
TextDocument
,
header
?:
TocEntry
,
toc
?:
TocEntry
[]):
vscode
.
Position
|
undefined
{
let
childRange
:
vscode
.
Position
|
undefined
;
if
(
header
&&
toc
)
{
...
...
@@ -210,7 +160,3 @@ function getFirstChildHeader(document: vscode.TextDocument, header?: TocEntry, t
}
return
undefined
;
}
function
rangeLinesEqual
(
range
:
vscode
.
Range
,
parent
:
vscode
.
Range
)
{
return
range
.
start
.
line
===
parent
.
start
.
line
&&
range
.
end
.
line
===
parent
.
end
.
line
;
}
extensions/markdown-language-features/src/test/smartSelect.test.ts
浏览文件 @
6e2aa0bf
...
...
@@ -335,7 +335,7 @@ suite('markdown.SmartSelect', () => {
`- content 2`
,
`- content 2`
));
assertNestedLineNumbersEqual
(
ranges
!
[
0
],
[
9
,
11
],
[
8
,
12
],
[
7
,
17
],
[
1
,
17
],
[
0
,
17
]);
assertNestedLineNumbersEqual
(
ranges
!
[
0
],
[
9
,
11
],
[
8
,
12
],
[
8
,
12
],
[
7
,
17
],
[
1
,
17
],
[
0
,
17
]);
});
test
(
'
Smart select fenced code block then list then rest of content on fenced line
'
,
async
()
=>
{
const
ranges
=
await
getSelectionRangesForDocument
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录