Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
841ef459
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,发现更多精彩内容 >>
提交
841ef459
编写于
9月 12, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More CharCode adoption
上级
34a85725
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
36 addition
and
33 deletion
+36
-33
src/vs/base/common/charCode.ts
src/vs/base/common/charCode.ts
+14
-1
src/vs/base/common/strings.ts
src/vs/base/common/strings.ts
+2
-4
src/vs/editor/common/viewLayout/viewLineParts.ts
src/vs/editor/common/viewLayout/viewLineParts.ts
+4
-6
src/vs/editor/common/viewLayout/viewLineRenderer.ts
src/vs/editor/common/viewLayout/viewLineRenderer.ts
+14
-21
src/vs/editor/test/common/viewLayout/viewLineRenderer.test.ts
...vs/editor/test/common/viewLayout/viewLineRenderer.test.ts
+2
-1
未找到文件。
src/vs/base/common/charCode.ts
浏览文件 @
841ef459
...
...
@@ -11,7 +11,7 @@
* Please leave the const keyword such that it gets inlined when compiled to JavaScript!
*/
export
const
enum
CharCode
{
Null
=
0
,
Tab
=
9
,
LineFeed
=
10
,
CarriageReturn
=
13
,
...
...
@@ -212,4 +212,17 @@ export const enum CharCode {
* The `~` character.
*/
Tilde
=
126
,
/**
* Unicode Character 'LINE SEPARATOR' (U+2028)
* http://www.fileformat.info/info/unicode/char/2028/index.htm
*/
LINE_SEPARATOR_2028
=
8232
,
/**
* UTF-8 BOM
* Unicode Character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF)
* http://www.fileformat.info/info/unicode/char/feff/index.htm
*/
UTF8_BOM
=
65279
}
\ No newline at end of file
src/vs/base/common/strings.ts
浏览文件 @
841ef459
...
...
@@ -550,12 +550,10 @@ export function removeAnsiEscapeCodes(str: string): string {
// -- UTF-8 BOM
const
__utf8_bom
=
65279
;
export
const
UTF8_BOM_CHARACTER
=
String
.
fromCharCode
(
__utf8_bom
);
export
const
UTF8_BOM_CHARACTER
=
String
.
fromCharCode
(
CharCode
.
UTF8_BOM
);
export
function
startsWithUTF8BOM
(
str
:
string
):
boolean
{
return
(
str
&&
str
.
length
>
0
&&
str
.
charCodeAt
(
0
)
===
__utf8_bom
);
return
(
str
&&
str
.
length
>
0
&&
str
.
charCodeAt
(
0
)
===
CharCode
.
UTF8_BOM
);
}
/**
...
...
src/vs/editor/common/viewLayout/viewLineParts.ts
浏览文件 @
841ef459
...
...
@@ -9,6 +9,7 @@ import {Arrays} from 'vs/editor/common/core/arrays';
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
ViewLineToken
,
ViewLineTokens
}
from
'
vs/editor/common/core/viewLineToken
'
;
import
{
InlineDecoration
}
from
'
vs/editor/common/viewModel/viewModel
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
function
cmpLineDecorations
(
a
:
InlineDecoration
,
b
:
InlineDecoration
):
number
{
return
Range
.
compareRangesUsingStarts
(
a
.
range
,
b
.
range
);
...
...
@@ -93,9 +94,6 @@ function trimEmptyTrailingPart(parts: ViewLineToken[], lineContent: string): Vie
return
parts
.
slice
(
0
,
parts
.
length
-
1
);
}
const
_tab
=
'
\t
'
.
charCodeAt
(
0
);
const
_space
=
'
'
.
charCodeAt
(
0
);
function
insertOneCustomLineDecoration
(
dest
:
InlineDecoration
[],
lineNumber
:
number
,
startColumn
:
number
,
endColumn
:
number
,
className
:
string
):
void
{
dest
.
push
(
new
InlineDecoration
(
new
Range
(
lineNumber
,
startColumn
,
lineNumber
,
endColumn
),
className
));
}
...
...
@@ -135,8 +133,8 @@ function insertWhitespaceLineDecorations(lineNumber:number, lineContent: string,
let
hasTab
=
false
;
for
(
let
i
=
Math
.
max
(
firstNonWhitespaceIndex
,
fauxIndentLength
);
i
<=
lastNonWhitespaceIndex
;
++
i
)
{
let
currentCharIsTab
=
lineContent
.
charCodeAt
(
i
)
===
_t
ab
;
if
(
currentCharIsTab
||
lineContent
.
charCodeAt
(
i
)
===
_s
pace
)
{
let
currentCharIsTab
=
lineContent
.
charCodeAt
(
i
)
===
CharCode
.
T
ab
;
if
(
currentCharIsTab
||
lineContent
.
charCodeAt
(
i
)
===
CharCode
.
S
pace
)
{
if
(
currentCharIsTab
)
{
hasTab
=
true
;
}
...
...
@@ -185,7 +183,7 @@ function insertCustomLineDecorationsWithStateMachine(lineNumber:number, lineCont
for
(
let
index
=
0
;
index
<
lineLength
;
index
++
)
{
let
chCode
=
lineContent
.
charCodeAt
(
index
);
if
(
chCode
===
_t
ab
)
{
if
(
chCode
===
CharCode
.
T
ab
)
{
tmpIndent
=
tabSize
;
}
else
{
tmpIndent
++
;
...
...
src/vs/editor/common/viewLayout/viewLineRenderer.ts
浏览文件 @
841ef459
...
...
@@ -5,6 +5,7 @@
'
use strict
'
;
import
{
ViewLineToken
}
from
'
vs/editor/common/core/viewLineToken
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
export
class
RenderLineInput
{
_renderLineInputBrand
:
void
;
...
...
@@ -49,16 +50,6 @@ export class RenderLineOutput {
}
}
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
_controlCharacterSequenceConversionStart
=
9216
;
const
_lineSeparator
=
'
\
u2028
'
.
charCodeAt
(
0
);
//http://www.fileformat.info/info/unicode/char/2028/index.htm
const
_bom
=
65279
;
export
function
renderLine
(
input
:
RenderLineInput
):
RenderLineOutput
{
const
lineText
=
input
.
lineContent
;
const
lineTextLength
=
lineText
.
length
;
...
...
@@ -92,6 +83,8 @@ function isWhitespace(type:string): boolean {
function
isControlCharacter
(
characterCode
:
number
):
boolean
{
return
characterCode
<
32
;
}
const
_controlCharacterSequenceConversionStart
=
9216
;
function
controlCharacterToPrintable
(
characterCode
:
number
):
string
{
return
String
.
fromCharCode
(
_controlCharacterSequenceConversionStart
+
characterCode
);
}
...
...
@@ -128,7 +121,7 @@ function renderLineActual(lineText: string, lineTextLength: number, tabSize: num
charOffsetInPartArr
[
charIndex
]
=
charOffsetInPart
;
let
charCode
=
lineText
.
charCodeAt
(
charIndex
);
if
(
charCode
===
_t
ab
)
{
if
(
charCode
===
CharCode
.
T
ab
)
{
let
insertSpacesCount
=
tabSize
-
(
charIndex
+
tabsCharDelta
)
%
tabSize
;
tabsCharDelta
+=
insertSpacesCount
-
1
;
charOffsetInPart
+=
insertSpacesCount
-
1
;
...
...
@@ -143,7 +136,7 @@ function renderLineActual(lineText: string, lineTextLength: number, tabSize: num
insertSpacesCount
--
;
}
}
else
{
// must be
_s
pace
// must be
CharCode.S
pace
partContent
+=
'
·
'
;
partContentCnt
++
;
}
...
...
@@ -175,7 +168,7 @@ function renderLineActual(lineText: string, lineTextLength: number, tabSize: num
let
charCode
=
lineText
.
charCodeAt
(
charIndex
);
switch
(
charCode
)
{
case
_t
ab
:
case
CharCode
.
T
ab
:
let
insertSpacesCount
=
tabSize
-
(
charIndex
+
tabsCharDelta
)
%
tabSize
;
tabsCharDelta
+=
insertSpacesCount
-
1
;
charOffsetInPart
+=
insertSpacesCount
-
1
;
...
...
@@ -185,32 +178,32 @@ function renderLineActual(lineText: string, lineTextLength: number, tabSize: num
}
break
;
case
_s
pace
:
case
CharCode
.
S
pace
:
out
+=
'
'
;
break
;
case
_lower
Than
:
case
CharCode
.
Less
Than
:
out
+=
'
<
'
;
break
;
case
_g
reaterThan
:
case
CharCode
.
G
reaterThan
:
out
+=
'
>
'
;
break
;
case
_a
mpersand
:
case
CharCode
.
A
mpersand
:
out
+=
'
&
'
;
break
;
case
0
:
case
CharCode
.
Null
:
out
+=
'
�
'
;
break
;
case
_bom
:
case
_lineSeparator
:
case
CharCode
.
UTF8_BOM
:
case
CharCode
.
LINE_SEPARATOR_2028
:
out
+=
'
\
ufffd
'
;
break
;
case
_c
arriageReturn
:
case
CharCode
.
C
arriageReturn
:
// zero width space, because carriage return would introduce a line break
out
+=
'
​
'
;
break
;
...
...
src/vs/editor/test/common/viewLayout/viewLineRenderer.test.ts
浏览文件 @
841ef459
...
...
@@ -7,6 +7,7 @@
import
*
as
assert
from
'
assert
'
;
import
{
renderLine
,
RenderLineInput
}
from
'
vs/editor/common/viewLayout/viewLineRenderer
'
;
import
{
ViewLineToken
}
from
'
vs/editor/common/core/viewLineToken
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
suite
(
'
viewLineRenderer.renderLine
'
,
()
=>
{
...
...
@@ -43,7 +44,7 @@ suite('viewLineRenderer.renderLine', () => {
test
(
'
replaces some bad characters
'
,
()
=>
{
assertCharacterReplacement
(
'
a
\
0b
'
,
4
,
'
a�b
'
,
[
0
,
1
,
2
,
3
]);
assertCharacterReplacement
(
'
a
'
+
String
.
fromCharCode
(
65279
)
+
'
b
'
,
4
,
'
a
\
ufffdb
'
,
[
0
,
1
,
2
,
3
]);
assertCharacterReplacement
(
'
a
'
+
String
.
fromCharCode
(
CharCode
.
UTF8_BOM
)
+
'
b
'
,
4
,
'
a
\
ufffdb
'
,
[
0
,
1
,
2
,
3
]);
assertCharacterReplacement
(
'
a
\
u2028b
'
,
4
,
'
a
\
ufffdb
'
,
[
0
,
1
,
2
,
3
]);
assertCharacterReplacement
(
'
a
\r
b
'
,
4
,
'
a​b
'
,
[
0
,
1
,
2
,
3
]);
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录