Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
04292e84
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,发现更多精彩内容 >>
未验证
提交
04292e84
编写于
3月 17, 2020
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce usage of IValidatedEditOperation.lines
上级
181d6ebc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
59 addition
and
7 deletion
+59
-7
src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.ts
...r/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.ts
+39
-5
src/vs/editor/common/model/tokensStore.ts
src/vs/editor/common/model/tokensStore.ts
+14
-2
src/vs/editor/test/common/model/linesTextBuffer/linesTextBuffer.test.ts
...test/common/model/linesTextBuffer/linesTextBuffer.test.ts
+6
-0
未找到文件。
src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.ts
浏览文件 @
04292e84
...
@@ -18,6 +18,9 @@ export interface IValidatedEditOperation {
...
@@ -18,6 +18,9 @@ export interface IValidatedEditOperation {
rangeOffset
:
number
;
rangeOffset
:
number
;
rangeLength
:
number
;
rangeLength
:
number
;
lines
:
string
[]
|
null
;
lines
:
string
[]
|
null
;
text
:
string
|
null
;
firstLine
:
string
|
null
;
lastLine
:
string
|
null
;
forceMoveMarkers
:
boolean
;
forceMoveMarkers
:
boolean
;
isAutoWhitespaceEdit
:
boolean
;
isAutoWhitespaceEdit
:
boolean
;
}
}
...
@@ -223,31 +226,52 @@ export class PieceTreeTextBuffer implements ITextBuffer {
...
@@ -223,31 +226,52 @@ export class PieceTreeTextBuffer implements ITextBuffer {
}
}
let
lines
:
string
[]
|
null
=
null
;
let
lines
:
string
[]
|
null
=
null
;
let
firstLine
:
string
|
null
=
null
;
let
lastLine
:
string
|
null
=
null
;
let
validText
:
string
|
null
=
null
;
if
(
op
.
text
)
{
if
(
op
.
text
)
{
const
eol
=
this
.
getEOL
();
lines
=
[];
lines
=
[];
let
linesLen
=
0
;
let
linesLen
=
0
;
let
lastLineStart
=
0
;
let
lastLineStart
=
0
;
let
textIsValid
=
true
;
for
(
let
j
=
0
,
len
=
op
.
text
.
length
;
j
<
len
;
j
++
)
{
for
(
let
j
=
0
,
len
=
op
.
text
.
length
;
j
<
len
;
j
++
)
{
const
chr
=
op
.
text
.
charCodeAt
(
j
);
const
chr
=
op
.
text
.
charCodeAt
(
j
);
if
(
chr
===
CharCode
.
CarriageReturn
)
{
if
(
chr
===
CharCode
.
CarriageReturn
)
{
if
(
j
+
1
<
len
&&
op
.
text
.
charCodeAt
(
j
+
1
)
===
CharCode
.
LineFeed
)
{
if
(
j
+
1
<
len
&&
op
.
text
.
charCodeAt
(
j
+
1
)
===
CharCode
.
LineFeed
)
{
// \r\n... case
// \r\n... case
if
(
eol
!==
'
\r\n
'
)
{
textIsValid
=
false
;
}
lines
[
linesLen
++
]
=
op
.
text
.
substring
(
lastLineStart
,
j
);
lines
[
linesLen
++
]
=
op
.
text
.
substring
(
lastLineStart
,
j
);
lastLineStart
=
j
+
2
;
lastLineStart
=
j
+
2
;
j
++
;
// skip \n
j
++
;
// skip \n
}
else
{
}
else
{
// \r... case
// \r... case
textIsValid
=
false
;
lines
[
linesLen
++
]
=
op
.
text
.
substring
(
lastLineStart
,
j
);
lines
[
linesLen
++
]
=
op
.
text
.
substring
(
lastLineStart
,
j
);
lastLineStart
=
j
+
1
;
lastLineStart
=
j
+
1
;
}
}
}
else
if
(
chr
===
CharCode
.
LineFeed
)
{
}
else
if
(
chr
===
CharCode
.
LineFeed
)
{
// \n... case
// \n... case
if
(
eol
!==
'
\n
'
)
{
textIsValid
=
false
;
}
lines
[
linesLen
++
]
=
op
.
text
.
substring
(
lastLineStart
,
j
);
lines
[
linesLen
++
]
=
op
.
text
.
substring
(
lastLineStart
,
j
);
lastLineStart
=
j
+
1
;
lastLineStart
=
j
+
1
;
}
}
}
}
lines
[
linesLen
++
]
=
op
.
text
.
substring
(
lastLineStart
,
op
.
text
.
length
);
lastLine
=
op
.
text
.
substring
(
lastLineStart
,
op
.
text
.
length
);
lines
[
linesLen
++
]
=
lastLine
;
if
(
textIsValid
)
{
validText
=
op
.
text
;
}
else
{
validText
=
lines
.
join
(
eol
);
}
firstLine
=
lines
[
0
];
}
}
operations
[
i
]
=
{
operations
[
i
]
=
{
...
@@ -257,6 +281,9 @@ export class PieceTreeTextBuffer implements ITextBuffer {
...
@@ -257,6 +281,9 @@ export class PieceTreeTextBuffer implements ITextBuffer {
rangeOffset
:
this
.
getOffsetAt
(
validatedRange
.
startLineNumber
,
validatedRange
.
startColumn
),
rangeOffset
:
this
.
getOffsetAt
(
validatedRange
.
startLineNumber
,
validatedRange
.
startColumn
),
rangeLength
:
this
.
getValueLengthInRange
(
validatedRange
),
rangeLength
:
this
.
getValueLengthInRange
(
validatedRange
),
lines
:
lines
,
lines
:
lines
,
text
:
validText
,
firstLine
:
firstLine
,
lastLine
:
lastLine
,
forceMoveMarkers
:
Boolean
(
op
.
forceMoveMarkers
),
forceMoveMarkers
:
Boolean
(
op
.
forceMoveMarkers
),
isAutoWhitespaceEdit
:
op
.
isAutoWhitespaceEdit
||
false
isAutoWhitespaceEdit
:
op
.
isAutoWhitespaceEdit
||
false
};
};
...
@@ -425,13 +452,20 @@ export class PieceTreeTextBuffer implements ITextBuffer {
...
@@ -425,13 +452,20 @@ export class PieceTreeTextBuffer implements ITextBuffer {
lastEndColumn
=
operation
.
range
.
endColumn
;
lastEndColumn
=
operation
.
range
.
endColumn
;
}
}
const
lines
=
result
.
join
(
''
).
split
(
'
\n
'
);
const
firstLine
=
lines
[
0
];
const
lastLine
=
lines
[
lines
.
length
-
1
];
return
{
return
{
sortIndex
:
0
,
sortIndex
:
0
,
identifier
:
operations
[
0
].
identifier
,
identifier
:
operations
[
0
].
identifier
,
range
:
entireEditRange
,
range
:
entireEditRange
,
rangeOffset
:
this
.
getOffsetAt
(
entireEditRange
.
startLineNumber
,
entireEditRange
.
startColumn
),
rangeOffset
:
this
.
getOffsetAt
(
entireEditRange
.
startLineNumber
,
entireEditRange
.
startColumn
),
rangeLength
:
this
.
getValueLengthInRange
(
entireEditRange
,
EndOfLinePreference
.
TextDefined
),
rangeLength
:
this
.
getValueLengthInRange
(
entireEditRange
,
EndOfLinePreference
.
TextDefined
),
lines
:
result
.
join
(
''
).
split
(
'
\n
'
),
lines
:
lines
,
text
:
lines
.
join
(
this
.
getEOL
()),
firstLine
:
firstLine
,
lastLine
:
lastLine
,
forceMoveMarkers
:
forceMoveMarkers
,
forceMoveMarkers
:
forceMoveMarkers
,
isAutoWhitespaceEdit
:
false
isAutoWhitespaceEdit
:
false
};
};
...
@@ -451,12 +485,12 @@ export class PieceTreeTextBuffer implements ITextBuffer {
...
@@ -451,12 +485,12 @@ export class PieceTreeTextBuffer implements ITextBuffer {
const
endLineNumber
=
op
.
range
.
endLineNumber
;
const
endLineNumber
=
op
.
range
.
endLineNumber
;
const
endColumn
=
op
.
range
.
endColumn
;
const
endColumn
=
op
.
range
.
endColumn
;
if
(
startLineNumber
===
endLineNumber
&&
startColumn
===
endColumn
&&
(
!
op
.
lines
||
op
.
lines
.
length
===
0
))
{
if
(
startLineNumber
===
endLineNumber
&&
startColumn
===
endColumn
&&
(
!
op
.
text
||
op
.
text
.
length
===
0
))
{
// no-op
// no-op
continue
;
continue
;
}
}
const
text
=
(
op
.
lines
?
op
.
lines
.
join
(
this
.
getEOL
())
:
''
)
;
const
text
=
op
.
text
?
op
.
text
:
''
;
if
(
text
)
{
if
(
text
)
{
// replacement
// replacement
...
...
src/vs/editor/common/model/tokensStore.ts
浏览文件 @
04292e84
...
@@ -11,10 +11,18 @@ import { ColorId, FontStyle, LanguageId, MetadataConsts, StandardTokenType, Toke
...
@@ -11,10 +11,18 @@ import { ColorId, FontStyle, LanguageId, MetadataConsts, StandardTokenType, Toke
import
{
writeUInt32BE
,
readUInt32BE
}
from
'
vs/base/common/buffer
'
;
import
{
writeUInt32BE
,
readUInt32BE
}
from
'
vs/base/common/buffer
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
export
function
countEOL
(
text
:
string
):
[
number
,
number
,
number
]
{
export
const
enum
StringEOL
{
Unknown
=
0
,
Invalid
=
3
,
LF
=
1
,
CRLF
=
2
}
export
function
countEOL
(
text
:
string
):
[
number
,
number
,
number
,
StringEOL
]
{
let
eolCount
=
0
;
let
eolCount
=
0
;
let
firstLineLength
=
0
;
let
firstLineLength
=
0
;
let
lastLineStart
=
0
;
let
lastLineStart
=
0
;
let
eol
:
StringEOL
=
StringEOL
.
Unknown
;
for
(
let
i
=
0
,
len
=
text
.
length
;
i
<
len
;
i
++
)
{
for
(
let
i
=
0
,
len
=
text
.
length
;
i
<
len
;
i
++
)
{
const
chr
=
text
.
charCodeAt
(
i
);
const
chr
=
text
.
charCodeAt
(
i
);
...
@@ -25,12 +33,16 @@ export function countEOL(text: string): [number, number, number] {
...
@@ -25,12 +33,16 @@ export function countEOL(text: string): [number, number, number] {
eolCount
++
;
eolCount
++
;
if
(
i
+
1
<
len
&&
text
.
charCodeAt
(
i
+
1
)
===
CharCode
.
LineFeed
)
{
if
(
i
+
1
<
len
&&
text
.
charCodeAt
(
i
+
1
)
===
CharCode
.
LineFeed
)
{
// \r\n... case
// \r\n... case
eol
|=
StringEOL
.
CRLF
;
i
++
;
// skip \n
i
++
;
// skip \n
}
else
{
}
else
{
// \r... case
// \r... case
eol
|=
StringEOL
.
Invalid
;
}
}
lastLineStart
=
i
+
1
;
lastLineStart
=
i
+
1
;
}
else
if
(
chr
===
CharCode
.
LineFeed
)
{
}
else
if
(
chr
===
CharCode
.
LineFeed
)
{
// \n... case
eol
|=
StringEOL
.
LF
;
if
(
eolCount
===
0
)
{
if
(
eolCount
===
0
)
{
firstLineLength
=
i
;
firstLineLength
=
i
;
}
}
...
@@ -41,7 +53,7 @@ export function countEOL(text: string): [number, number, number] {
...
@@ -41,7 +53,7 @@ export function countEOL(text: string): [number, number, number] {
if
(
eolCount
===
0
)
{
if
(
eolCount
===
0
)
{
firstLineLength
=
text
.
length
;
firstLineLength
=
text
.
length
;
}
}
return
[
eolCount
,
firstLineLength
,
text
.
length
-
lastLineStart
];
return
[
eolCount
,
firstLineLength
,
text
.
length
-
lastLineStart
,
eol
];
}
}
function
getDefaultMetadata
(
topLevelLanguageId
:
LanguageId
):
number
{
function
getDefaultMetadata
(
topLevelLanguageId
:
LanguageId
):
number
{
...
...
src/vs/editor/test/common/model/linesTextBuffer/linesTextBuffer.test.ts
浏览文件 @
04292e84
...
@@ -19,6 +19,9 @@ suite('PieceTreeTextBuffer._getInverseEdits', () => {
...
@@ -19,6 +19,9 @@ suite('PieceTreeTextBuffer._getInverseEdits', () => {
rangeOffset
:
0
,
rangeOffset
:
0
,
rangeLength
:
0
,
rangeLength
:
0
,
lines
:
text
,
lines
:
text
,
text
:
text
?
text
.
join
(
'
\n
'
)
:
null
,
firstLine
:
text
?
text
[
0
]
:
null
,
lastLine
:
text
?
text
[
text
.
length
-
1
]
:
null
,
forceMoveMarkers
:
false
,
forceMoveMarkers
:
false
,
isAutoWhitespaceEdit
:
false
isAutoWhitespaceEdit
:
false
};
};
...
@@ -270,6 +273,9 @@ suite('PieceTreeTextBuffer._toSingleEditOperation', () => {
...
@@ -270,6 +273,9 @@ suite('PieceTreeTextBuffer._toSingleEditOperation', () => {
rangeOffset
:
rangeOffset
,
rangeOffset
:
rangeOffset
,
rangeLength
:
rangeLength
,
rangeLength
:
rangeLength
,
lines
:
text
,
lines
:
text
,
text
:
text
?
text
.
join
(
'
\n
'
)
:
null
,
firstLine
:
text
?
text
[
0
]
:
null
,
lastLine
:
text
?
text
[
text
.
length
-
1
]
:
null
,
forceMoveMarkers
:
false
,
forceMoveMarkers
:
false
,
isAutoWhitespaceEdit
:
false
isAutoWhitespaceEdit
:
false
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录