Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
31a33120
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
31a33120
编写于
7月 08, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #8775: Always check that a link cannot end in certain characters (even when at end of line)
上级
a5cf4a58
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
27 deletion
+26
-27
src/vs/editor/common/modes/linkComputer.ts
src/vs/editor/common/modes/linkComputer.ts
+22
-25
src/vs/editor/test/common/modes/linkComputer.test.ts
src/vs/editor/test/common/modes/linkComputer.test.ts
+4
-2
未找到文件。
src/vs/editor/common/modes/linkComputer.ts
浏览文件 @
31a33120
...
...
@@ -55,8 +55,8 @@ class CharacterClassifier {
private
_map
:
CharacterClass
[];
constructor
()
{
var
FORCE_TERMINATION_CHARACTERS
=
'
\t
<>
\'\
"、。。、,.:;?!@#$%&*‘“〈《「『【〔([{「」}])〕】』」》〉”’`~…
'
;
var
CANNOT_END_WITH_CHARACTERS
=
'
.,;
'
;
const
FORCE_TERMINATION_CHARACTERS
=
'
\t
<>
\'\
"、。。、,.:;?!@#$%&*‘“〈《「『【〔([{「」}])〕】』」》〉”’`~…
'
;
const
CANNOT_END_WITH_CHARACTERS
=
'
.,;
'
;
this
.
_asciiMap
=
[];
for
(
let
i
=
0
;
i
<
256
;
i
++
)
{
...
...
@@ -95,25 +95,34 @@ class CharacterClassifier {
}
}
c
lass
LinkComputer
{
c
onst
characterClassifier
=
new
CharacterClassifier
();
private
static
_characterClassifier
=
new
CharacterClassifier
();
class
LinkComputer
{
private
static
_createLink
(
line
:
string
,
lineNumber
:
number
,
linkBeginIndex
:
number
,
linkEndIndex
:
number
):
ILink
{
// Do not allow to end link in certain characters...
let
lastIncludedCharIndex
=
linkEndIndex
-
1
;
do
{
const
chCode
=
line
.
charCodeAt
(
lastIncludedCharIndex
);
const
chClass
=
characterClassifier
.
classify
(
chCode
);
if
(
chClass
!==
CharacterClass
.
CannotEndIn
)
{
break
;
}
lastIncludedCharIndex
--
;
}
while
(
lastIncludedCharIndex
>
linkBeginIndex
);
return
{
range
:
{
startLineNumber
:
lineNumber
,
startColumn
:
linkBeginIndex
+
1
,
endLineNumber
:
lineNumber
,
endColumn
:
l
inkEndIndex
+
1
endColumn
:
l
astIncludedCharIndex
+
2
},
url
:
line
.
substring
(
linkBeginIndex
,
l
inkEndIndex
)
url
:
line
.
substring
(
linkBeginIndex
,
l
astIncludedCharIndex
+
1
)
};
}
public
static
computeLinks
(
model
:
ILinkComputerTarget
):
ILink
[]
{
const
characterClassifier
=
LinkComputer
.
_characterClassifier
;
let
result
:
ILink
[]
=
[];
for
(
let
i
=
1
,
lineCount
=
model
.
getLineCount
();
i
<=
lineCount
;
i
++
)
{
const
line
=
model
.
getLineContent
(
i
);
...
...
@@ -131,7 +140,7 @@ class LinkComputer {
let
resetStateMachine
=
false
;
if
(
state
===
ACCEPT_STATE
)
{
le
t
chCode
=
line
.
charCodeAt
(
j
);
cons
t
chCode
=
line
.
charCodeAt
(
j
);
let
chClass
:
CharacterClass
;
switch
(
chCode
)
{
case
_openParens
:
...
...
@@ -161,24 +170,12 @@ class LinkComputer {
// Check if character terminates link
if
(
chClass
===
CharacterClass
.
ForceTermination
)
{
// Do not allow to end link in certain characters...
let
lastIncludedCharIndex
=
j
-
1
;
do
{
chCode
=
line
.
charCodeAt
(
lastIncludedCharIndex
);
chClass
=
characterClassifier
.
classify
(
chCode
);
if
(
chClass
!==
CharacterClass
.
CannotEndIn
)
{
break
;
}
lastIncludedCharIndex
--
;
}
while
(
lastIncludedCharIndex
>
linkBeginIndex
);
result
.
push
(
LinkComputer
.
_createLink
(
line
,
i
,
linkBeginIndex
,
lastIncludedCharIndex
+
1
));
result
.
push
(
LinkComputer
.
_createLink
(
line
,
i
,
linkBeginIndex
,
j
));
resetStateMachine
=
true
;
}
}
else
if
(
state
===
END_STATE
)
{
le
t
chCode
=
line
.
charCodeAt
(
j
);
le
t
chClass
=
characterClassifier
.
classify
(
chCode
);
cons
t
chCode
=
line
.
charCodeAt
(
j
);
cons
t
chClass
=
characterClassifier
.
classify
(
chCode
);
// Check if character terminates link
if
(
chClass
===
CharacterClass
.
ForceTermination
)
{
...
...
@@ -187,7 +184,7 @@ class LinkComputer {
state
=
ACCEPT_STATE
;
}
}
else
{
le
t
ch
=
line
.
charAt
(
j
);
cons
t
ch
=
line
.
charAt
(
j
);
if
(
STATE_MAP
[
state
].
hasOwnProperty
(
ch
))
{
state
=
STATE_MAP
[
state
][
ch
];
}
else
{
...
...
src/vs/editor/test/common/modes/linkComputer.test.ts
浏览文件 @
31a33120
...
...
@@ -181,7 +181,9 @@ suite('Editor Modes - Link Computer', () => {
'
x = "file://shäres/foo.bar";
'
,
'
file://shäres/foo.bar
'
);
// foo bar (see http://www.w3schools.com/tags/att_iframe_sandbox.asp)
assertLink
(
'
Some text, then http://www.bing.com.
'
,
'
http://www.bing.com
'
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录