Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
d55b6850
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
d55b6850
编写于
1月 15, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify renderLine
上级
ec6d3c6b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
106 addition
and
114 deletion
+106
-114
src/vs/editor/common/viewLayout/viewLineRenderer.ts
src/vs/editor/common/viewLayout/viewLineRenderer.ts
+105
-113
src/vs/editor/test/common/viewLayout/viewLineRenderer.test.ts
...vs/editor/test/common/viewLayout/viewLineRenderer.test.ts
+1
-1
未找到文件。
src/vs/editor/common/viewLayout/viewLineRenderer.ts
浏览文件 @
d55b6850
...
...
@@ -20,21 +20,22 @@ export interface IRenderLineOutput {
output
:
string
[];
}
let
_space
=
'
'
.
charCodeAt
(
0
);
let
_tab
=
'
\t
'
.
charCodeAt
(
0
);
let
_lowerThan
=
'
<
'
.
charCodeAt
(
0
);
let
_greaterThan
=
'
>
'
.
charCodeAt
(
0
);
let
_ampersand
=
'
&
'
.
charCodeAt
(
0
);
let
_carriageReturn
=
'
\r
'
.
charCodeAt
(
0
);
let
_lineSeparator
=
'
\
u2028
'
.
charCodeAt
(
0
);
//http://www.fileformat.info/info/unicode/char/2028/index.htm
let
_bom
=
65279
;
let
_replacementCharacter
=
'
\
ufffd
'
;
const
_space
=
'
'
.
charCodeAt
(
0
);
const
_tab
=
'
\t
'
.
charCodeAt
(
0
);
const
_lowerThan
=
'
<
'
.
charCodeAt
(
0
);
const
_greaterThan
=
'
>
'
.
charCodeAt
(
0
);
const
_ampersand
=
'
&
'
.
charCodeAt
(
0
);
const
_carriageReturn
=
'
\r
'
.
charCodeAt
(
0
);
const
_lineSeparator
=
'
\
u2028
'
.
charCodeAt
(
0
);
//http://www.fileformat.info/info/unicode/char/2028/index.htm
const
_bom
=
65279
;
export
function
renderLine
(
input
:
IRenderLineInput
):
IRenderLineOutput
{
const
lineText
=
input
.
lineContent
;
let
lineTextLength
=
lineText
.
length
;
const
stopRenderingLineAfter
=
input
.
stopRenderingLineAfter
;
const
lineTextLength
=
lineText
.
length
;
const
tabSize
=
input
.
tabSize
;
const
actualLineParts
=
input
.
parts
;
const
renderWhitespace
=
input
.
renderWhitespace
;
const
charBreakIndex
=
(
input
.
stopRenderingLineAfter
===
-
1
?
lineTextLength
:
input
.
stopRenderingLineAfter
-
1
);
if
(
lineTextLength
===
0
)
{
return
{
...
...
@@ -45,121 +46,112 @@ export function renderLine(input:IRenderLineInput): IRenderLineOutput {
};
}
let
result
:
IRenderLineOutput
=
{
charOffsetInPart
:
[],
lastRenderedPartIndex
:
0
,
output
:
[]
};
result
.
output
.
push
(
'
<span>
'
);
let
partClassName
:
string
,
partIndex
=
-
1
,
nextPartIndex
=
0
,
tabsCharDelta
=
0
,
charOffsetInPart
=
0
,
append
=
''
,
renderWhitespace
=
false
;
let
actualLineParts
=
input
.
parts
;
if
(
actualLineParts
.
length
===
0
)
{
throw
new
Error
(
'
Cannot render non empty line without line parts!
'
);
}
if
(
stopRenderingLineAfter
!==
-
1
&&
lineTextLength
>
stopRenderingLineAfter
-
1
)
{
append
=
lineText
.
substr
(
stopRenderingLineAfter
-
1
,
1
)
;
lineTextLength
=
stopRenderingLineAfter
-
1
;
}
let
charIndex
=
0
;
let
out
:
string
[]
=
[]
;
let
charOffsetInPartArr
:
number
[]
=
[]
;
let
charOffsetInPart
=
0
;
for
(
let
i
=
0
;
i
<
lineTextLength
;
i
++
)
{
if
(
i
===
nextPartIndex
)
{
partIndex
++
;
nextPartIndex
=
(
partIndex
+
1
<
actualLineParts
.
length
?
actualLineParts
[
partIndex
+
1
].
startIndex
:
Number
.
MAX_VALUE
);
if
(
i
>
0
)
{
result
.
output
.
push
(
'
</span>
'
);
}
result
.
output
.
push
(
'
<span class="
'
);
partClassName
=
'
token
'
+
actualLineParts
[
partIndex
].
type
.
replace
(
/
[^
a-z0-9
\-]
/gi
,
'
'
);
if
(
input
.
renderWhitespace
)
{
renderWhitespace
=
partClassName
.
indexOf
(
'
whitespace
'
)
>=
0
;
}
result
.
output
.
push
(
partClassName
);
result
.
output
.
push
(
'
">
'
);
out
.
push
(
'
<span>
'
);
for
(
let
partIndex
=
0
,
partIndexLen
=
actualLineParts
.
length
;
partIndex
<
partIndexLen
;
partIndex
++
)
{
let
part
=
actualLineParts
[
partIndex
];
out
.
push
(
'
<span class="
'
);
out
.
push
(
'
token
'
);
out
.
push
(
part
.
type
.
replace
(
/
[^
a-z0-9
\-]
/gi
,
'
'
));
out
.
push
(
'
">
'
);
charOffsetInPart
=
0
;
let
partRendersWhitespace
=
false
;
if
(
renderWhitespace
)
{
partRendersWhitespace
=
(
/whitespace$/
.
test
(
part
.
type
));
}
result
.
charOffsetInPart
[
i
]
=
charOffsetInPart
;
let
charCode
=
lineText
.
charCodeAt
(
i
);
switch
(
charCode
)
{
case
_tab
:
let
insertSpacesCount
=
tabSize
-
(
i
+
tabsCharDelta
)
%
tabSize
;
tabsCharDelta
+=
insertSpacesCount
-
1
;
charOffsetInPart
+=
insertSpacesCount
-
1
;
if
(
insertSpacesCount
>
0
)
{
result
.
output
.
push
(
renderWhitespace
?
'
→
'
:
'
'
);
insertSpacesCount
--
;
}
while
(
insertSpacesCount
>
0
)
{
result
.
output
.
push
(
'
'
);
insertSpacesCount
--
;
}
break
;
case
_space
:
result
.
output
.
push
(
renderWhitespace
?
'
·
'
:
'
'
);
break
;
case
_lowerThan
:
result
.
output
.
push
(
'
<
'
);
break
;
case
_greaterThan
:
result
.
output
.
push
(
'
>
'
);
break
;
case
_ampersand
:
result
.
output
.
push
(
'
&
'
);
break
;
case
0
:
result
.
output
.
push
(
'
�
'
);
break
;
case
_bom
:
case
_lineSeparator
:
result
.
output
.
push
(
_replacementCharacter
);
break
;
case
_carriageReturn
:
// zero width space, because carriage return would introduce a line break
result
.
output
.
push
(
'
​
'
);
break
;
default
:
result
.
output
.
push
(
lineText
.
charAt
(
i
));
let
toCharIndex
=
lineTextLength
;
if
(
partIndex
+
1
<
partIndexLen
)
{
toCharIndex
=
Math
.
min
(
lineTextLength
,
actualLineParts
[
partIndex
+
1
].
startIndex
);
}
charOffsetInPart
++
;
charOffsetInPart
=
0
;
let
tabsCharDelta
=
0
;
for
(;
charIndex
<
toCharIndex
;
charIndex
++
)
{
charOffsetInPartArr
[
charIndex
]
=
charOffsetInPart
;
let
charCode
=
lineText
.
charCodeAt
(
charIndex
);
switch
(
charCode
)
{
case
_tab
:
let
insertSpacesCount
=
tabSize
-
(
charIndex
+
tabsCharDelta
)
%
tabSize
;
tabsCharDelta
+=
insertSpacesCount
-
1
;
charOffsetInPart
+=
insertSpacesCount
-
1
;
if
(
insertSpacesCount
>
0
)
{
out
.
push
(
partRendersWhitespace
?
'
→
'
:
'
'
);
insertSpacesCount
--
;
}
while
(
insertSpacesCount
>
0
)
{
out
.
push
(
'
'
);
insertSpacesCount
--
;
}
break
;
case
_space
:
out
.
push
(
partRendersWhitespace
?
'
·
'
:
'
'
);
break
;
case
_lowerThan
:
out
.
push
(
'
<
'
);
break
;
case
_greaterThan
:
out
.
push
(
'
>
'
);
break
;
case
_ampersand
:
out
.
push
(
'
&
'
);
break
;
case
0
:
out
.
push
(
'
�
'
);
break
;
case
_bom
:
case
_lineSeparator
:
out
.
push
(
'
\
ufffd
'
);
break
;
case
_carriageReturn
:
// zero width space, because carriage return would introduce a line break
out
.
push
(
'
​
'
);
break
;
default
:
out
.
push
(
lineText
.
charAt
(
charIndex
));
}
charOffsetInPart
++
;
if
(
charIndex
>=
charBreakIndex
)
{
out
.
push
(
'
…</span></span>
'
);
charOffsetInPartArr
[
charOffsetInPartArr
.
length
-
1
]
++
;
return
{
charOffsetInPart
:
charOffsetInPartArr
,
lastRenderedPartIndex
:
partIndex
,
output
:
out
};
}
}
out
.
push
(
'
</span>
'
);
}
result
.
outp
ut
.
push
(
'
</span>
'
);
o
ut
.
push
(
'
</span>
'
);
// When getting client rects for the last character, we will position the
// text range at the end of the span, insteaf of at the beginning of next span
result
.
charOffsetInPart
[
lineTextLength
]
=
charOffsetInPart
;
// In case we stop rendering, we record here the index of the last span
// that should be used for getting client rects
result
.
lastRenderedPartIndex
=
partIndex
;
if
(
append
.
length
>
0
)
{
result
.
output
.
push
(
'
<span class="
'
);
result
.
output
.
push
(
partClassName
);
result
.
output
.
push
(
'
" style="color:grey">
'
);
result
.
output
.
push
(
append
);
result
.
output
.
push
(
'
…</span>
'
);
}
result
.
output
.
push
(
'
</span>
'
);
charOffsetInPartArr
.
push
(
charOffsetInPart
);
return
result
;
return
{
charOffsetInPart
:
charOffsetInPartArr
,
lastRenderedPartIndex
:
actualLineParts
.
length
-
1
,
output
:
out
};
}
src/vs/editor/test/common/viewLayout/viewLineRenderer.test.ts
浏览文件 @
d55b6850
...
...
@@ -115,7 +115,7 @@ suite('viewLineRenderer.renderLine', () => {
'
<span class="token 2">l</span>
'
,
'
<span class="token 3">l</span>
'
,
'
<span class="token 4">o</span>
'
,
'
<span class="token
4" style="color:grey"> …</span>
'
// bug, token should be 5, and space should be
'
<span class="token
5"> …</span>
'
].
join
(
''
);
assert
.
equal
(
_actual
.
output
.
join
(
''
),
'
<span>
'
+
expectedOutput
+
'
</span>
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录