Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
5507f635
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,发现更多精彩内容 >>
提交
5507f635
编写于
1月 15, 2018
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move RawContentChange events creation to TextModel
上级
27f7c0bc
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
78 addition
and
27 deletion
+78
-27
src/vs/editor/common/model.ts
src/vs/editor/common/model.ts
+1
-2
src/vs/editor/common/model/linesTextBuffer/linesTextBuffer.ts
...vs/editor/common/model/linesTextBuffer/linesTextBuffer.ts
+8
-16
src/vs/editor/common/model/textModel.ts
src/vs/editor/common/model/textModel.ts
+68
-6
src/vs/editor/common/viewModel/splitLinesCollection.ts
src/vs/editor/common/viewModel/splitLinesCollection.ts
+1
-0
src/vs/editor/test/common/model/model.test.ts
src/vs/editor/test/common/model/model.test.ts
+0
-3
未找到文件。
src/vs/editor/common/model.ts
浏览文件 @
5507f635
...
...
@@ -12,7 +12,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import
{
Position
,
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
Range
,
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
ModelRawContentChangedEvent
,
IModelContentChangedEvent
,
IModelDecorationsChangedEvent
,
IModelLanguageChangedEvent
,
IModelOptionsChangedEvent
,
IModelLanguageConfigurationChangedEvent
,
IModelTokensChangedEvent
,
IModelContentChange
,
ModelRawChange
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
{
ModelRawContentChangedEvent
,
IModelContentChangedEvent
,
IModelDecorationsChangedEvent
,
IModelLanguageChangedEvent
,
IModelOptionsChangedEvent
,
IModelLanguageConfigurationChangedEvent
,
IModelTokensChangedEvent
,
IModelContentChange
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
{
ThemeColor
}
from
'
vs/platform/theme/common/themeService
'
;
/**
...
...
@@ -1098,7 +1098,6 @@ export class ApplyEditsResult {
constructor
(
public
readonly
reverseEdits
:
IIdentifiedSingleEditOperation
[],
public
readonly
rawChanges
:
ModelRawChange
[],
public
readonly
changes
:
IInternalModelContentChange
[],
public
readonly
trimAutoWhitespaceLineNumbers
:
number
[]
)
{
}
...
...
src/vs/editor/common/model/linesTextBuffer/linesTextBuffer.ts
浏览文件 @
5507f635
...
...
@@ -9,7 +9,6 @@ import { Position } from 'vs/editor/common/core/position';
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
*
as
arrays
from
'
vs/base/common/arrays
'
;
import
{
PrefixSumComputer
}
from
'
vs/editor/common/viewModel/prefixSumComputer
'
;
import
{
ModelRawChange
,
ModelRawLineChanged
,
ModelRawLinesDeleted
,
ModelRawLinesInserted
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
{
ISingleEditOperationIdentifier
,
IIdentifiedSingleEditOperation
,
EndOfLinePreference
,
ITextBuffer
,
ApplyEditsResult
,
IInternalModelContentChange
}
from
'
vs/editor/common/model
'
;
export
interface
IValidatedEditOperation
{
...
...
@@ -252,7 +251,7 @@ export class LinesTextBuffer implements ITextBuffer {
public
applyEdits
(
rawOperations
:
IIdentifiedSingleEditOperation
[],
recordTrimAutoWhitespace
:
boolean
):
ApplyEditsResult
{
if
(
rawOperations
.
length
===
0
)
{
return
new
ApplyEditsResult
([],
[],
[]
,
[]
);
return
new
ApplyEditsResult
([],
[],
[]);
}
let
mightContainRTL
=
this
.
_mightContainRTL
;
...
...
@@ -341,7 +340,7 @@ export class LinesTextBuffer implements ITextBuffer {
this
.
_mightContainRTL
=
mightContainRTL
;
this
.
_mightContainNonBasicASCII
=
mightContainNonBasicASCII
;
const
[
rawContentChanges
,
contentChanges
]
=
this
.
_doApplyEdits
(
operations
);
const
contentChanges
=
this
.
_doApplyEdits
(
operations
);
let
trimAutoWhitespaceLineNumbers
:
number
[]
=
null
;
if
(
recordTrimAutoWhitespace
&&
newTrimAutoWhitespaceCandidates
.
length
>
0
)
{
...
...
@@ -369,7 +368,6 @@ export class LinesTextBuffer implements ITextBuffer {
return
new
ApplyEditsResult
(
reverseOperations
,
rawContentChanges
,
contentChanges
,
trimAutoWhitespaceLineNumbers
);
...
...
@@ -451,18 +449,16 @@ export class LinesTextBuffer implements ITextBuffer {
};
}
private
_setLineContent
(
lineNumber
:
number
,
content
:
string
,
rawContentChanges
:
ModelRawChange
[]
):
void
{
private
_setLineContent
(
lineNumber
:
number
,
content
:
string
):
void
{
this
.
_lines
[
lineNumber
-
1
]
=
content
;
this
.
_lineStarts
.
changeValue
(
lineNumber
-
1
,
content
.
length
+
this
.
_EOL
.
length
);
rawContentChanges
.
push
(
new
ModelRawLineChanged
(
lineNumber
,
content
));
}
private
_doApplyEdits
(
operations
:
IValidatedEditOperation
[]):
[
ModelRawChange
[],
IInternalModelContentChange
[]
]
{
private
_doApplyEdits
(
operations
:
IValidatedEditOperation
[]):
IInternalModelContentChange
[
]
{
// Sort operations descending
operations
.
sort
(
LinesTextBuffer
.
_sortOpsDescending
);
let
rawContentChanges
:
ModelRawChange
[]
=
[];
let
contentChanges
:
IInternalModelContentChange
[]
=
[];
for
(
let
i
=
0
,
len
=
operations
.
length
;
i
<
len
;
i
++
)
{
...
...
@@ -497,7 +493,7 @@ export class LinesTextBuffer implements ITextBuffer {
);
}
this
.
_setLineContent
(
editLineNumber
,
editText
,
rawContentChanges
);
this
.
_setLineContent
(
editLineNumber
,
editText
);
}
if
(
editingLinesCnt
<
deletingLinesCnt
)
{
...
...
@@ -507,12 +503,10 @@ export class LinesTextBuffer implements ITextBuffer {
const
endLineRemains
=
this
.
_lines
[
endLineNumber
-
1
].
substring
(
endColumn
-
1
);
// Reconstruct first line
this
.
_setLineContent
(
spliceStartLineNumber
,
this
.
_lines
[
spliceStartLineNumber
-
1
]
+
endLineRemains
,
rawContentChanges
);
this
.
_setLineContent
(
spliceStartLineNumber
,
this
.
_lines
[
spliceStartLineNumber
-
1
]
+
endLineRemains
);
this
.
_lines
.
splice
(
spliceStartLineNumber
,
endLineNumber
-
spliceStartLineNumber
);
this
.
_lineStarts
.
removeValues
(
spliceStartLineNumber
,
endLineNumber
-
spliceStartLineNumber
);
rawContentChanges
.
push
(
new
ModelRawLinesDeleted
(
spliceStartLineNumber
+
1
,
endLineNumber
));
}
if
(
editingLinesCnt
<
insertingLinesCnt
)
{
...
...
@@ -527,7 +521,7 @@ export class LinesTextBuffer implements ITextBuffer {
// Split last line
const
leftoverLine
=
this
.
_lines
[
spliceLineNumber
-
1
].
substring
(
spliceColumn
-
1
);
this
.
_setLineContent
(
spliceLineNumber
,
this
.
_lines
[
spliceLineNumber
-
1
].
substring
(
0
,
spliceColumn
-
1
)
,
rawContentChanges
);
this
.
_setLineContent
(
spliceLineNumber
,
this
.
_lines
[
spliceLineNumber
-
1
].
substring
(
0
,
spliceColumn
-
1
));
// Lines in the middle
let
newLines
:
string
[]
=
new
Array
<
string
>
(
insertingLinesCnt
-
editingLinesCnt
);
...
...
@@ -540,8 +534,6 @@ export class LinesTextBuffer implements ITextBuffer {
newLinesLengths
[
newLines
.
length
-
1
]
+=
leftoverLine
.
length
;
this
.
_lines
=
arrays
.
arrayInsert
(
this
.
_lines
,
startLineNumber
+
editingLinesCnt
,
newLines
);
this
.
_lineStarts
.
insertValues
(
startLineNumber
+
editingLinesCnt
,
newLinesLengths
);
rawContentChanges
.
push
(
new
ModelRawLinesInserted
(
spliceLineNumber
+
1
,
startLineNumber
+
insertingLinesCnt
,
newLines
));
}
const
contentChangeRange
=
new
Range
(
startLineNumber
,
startColumn
,
endLineNumber
,
endColumn
);
...
...
@@ -556,7 +548,7 @@ export class LinesTextBuffer implements ITextBuffer {
});
}
return
[
rawContentChanges
,
contentChanges
]
;
return
contentChanges
;
}
/**
...
...
src/vs/editor/common/model/textModel.ts
浏览文件 @
5507f635
...
...
@@ -11,7 +11,7 @@ import { LanguageIdentifier, TokenizationRegistry, LanguageId } from 'vs/editor/
import
{
EditStack
}
from
'
vs/editor/common/model/editStack
'
;
import
{
Range
,
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
ModelRawContentChangedEvent
,
IModelDecorationsChangedEvent
,
IModelLanguageChangedEvent
,
IModelLanguageConfigurationChangedEvent
,
IModelTokensChangedEvent
,
IModelOptionsChangedEvent
,
IModelContentChangedEvent
,
InternalModelContentChangeEvent
,
ModelRawFlush
,
ModelRawEOLChanged
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
{
ModelRawContentChangedEvent
,
IModelDecorationsChangedEvent
,
IModelLanguageChangedEvent
,
IModelLanguageConfigurationChangedEvent
,
IModelTokensChangedEvent
,
IModelOptionsChangedEvent
,
IModelContentChangedEvent
,
InternalModelContentChangeEvent
,
ModelRawFlush
,
ModelRawEOLChanged
,
ModelRawChange
,
ModelRawLineChanged
,
ModelRawLinesDeleted
,
ModelRawLinesInserted
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
IMarkdownString
}
from
'
vs/base/common/htmlContent
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
...
...
@@ -1033,21 +1033,83 @@ export class TextModel extends Disposable implements model.ITextModel {
}
}
private
static
_eolCount
(
text
:
string
):
number
{
let
eolCount
=
0
;
for
(
let
i
=
0
,
len
=
text
.
length
;
i
<
len
;
i
++
)
{
const
chr
=
text
.
charCodeAt
(
i
);
if
(
chr
===
CharCode
.
CarriageReturn
)
{
eolCount
++
;
if
(
i
+
1
<
len
&&
text
.
charCodeAt
(
i
+
1
)
===
CharCode
.
LineFeed
)
{
// \r\n... case
i
++
;
// skip \n
}
else
{
// \r... case
}
}
else
if
(
chr
===
CharCode
.
LineFeed
)
{
eolCount
++
;
}
}
return
eolCount
;
}
private
_applyEdits
(
rawOperations
:
model
.
IIdentifiedSingleEditOperation
[]):
model
.
IIdentifiedSingleEditOperation
[]
{
for
(
let
i
=
0
,
len
=
rawOperations
.
length
;
i
<
len
;
i
++
)
{
rawOperations
[
i
].
range
=
this
.
validateRange
(
rawOperations
[
i
].
range
);
}
const
oldLineCount
=
this
.
_buffer
.
getLineCount
();
const
result
=
this
.
_buffer
.
applyEdits
(
rawOperations
,
this
.
_options
.
trimAutoWhitespace
);
const
rawContentChanges
=
result
.
rawChanges
;
const
newLineCount
=
this
.
_buffer
.
getLineCount
();
const
contentChanges
=
result
.
changes
;
this
.
_trimAutoWhitespaceLines
=
result
.
trimAutoWhitespaceLineNumbers
;
if
(
rawContentChanges
.
length
!==
0
||
contentChanges
.
length
!==
0
)
{
if
(
contentChanges
.
length
!==
0
)
{
let
rawContentChanges
:
ModelRawChange
[]
=
[];
let
lineCount
=
oldLineCount
;
for
(
let
i
=
0
,
len
=
contentChanges
.
length
;
i
<
len
;
i
++
)
{
const
c
ontentC
hange
=
contentChanges
[
i
];
this
.
_tokens
.
applyEdits
(
c
ontentChange
.
range
,
contentC
hange
.
lines
);
const
change
=
contentChanges
[
i
];
this
.
_tokens
.
applyEdits
(
c
hange
.
range
,
c
hange
.
lines
);
this
.
_onDidChangeDecorations
.
fire
();
this
.
_decorationsTree
.
acceptReplace
(
contentChange
.
rangeOffset
,
contentChange
.
rangeLength
,
contentChange
.
text
.
length
,
contentChange
.
forceMoveMarkers
);
this
.
_decorationsTree
.
acceptReplace
(
change
.
rangeOffset
,
change
.
rangeLength
,
change
.
text
.
length
,
change
.
forceMoveMarkers
);
const
startLineNumber
=
change
.
range
.
startLineNumber
;
const
endLineNumber
=
change
.
range
.
endLineNumber
;
const
deletingLinesCnt
=
endLineNumber
-
startLineNumber
;
const
insertingLinesCnt
=
TextModel
.
_eolCount
(
change
.
text
);
const
editingLinesCnt
=
Math
.
min
(
deletingLinesCnt
,
insertingLinesCnt
);
const
changeLineCountDelta
=
(
insertingLinesCnt
-
deletingLinesCnt
);
for
(
let
j
=
editingLinesCnt
;
j
>=
0
;
j
--
)
{
const
editLineNumber
=
startLineNumber
+
j
;
const
currentEditLineNumber
=
newLineCount
-
lineCount
-
changeLineCountDelta
+
editLineNumber
;
rawContentChanges
.
push
(
new
ModelRawLineChanged
(
editLineNumber
,
this
.
getLineContent
(
currentEditLineNumber
)));
}
if
(
editingLinesCnt
<
deletingLinesCnt
)
{
// Must delete some lines
const
spliceStartLineNumber
=
startLineNumber
+
editingLinesCnt
;
rawContentChanges
.
push
(
new
ModelRawLinesDeleted
(
spliceStartLineNumber
+
1
,
endLineNumber
));
}
if
(
editingLinesCnt
<
insertingLinesCnt
)
{
// Must insert some lines
const
spliceLineNumber
=
startLineNumber
+
editingLinesCnt
;
const
cnt
=
insertingLinesCnt
-
editingLinesCnt
;
const
fromLineNumber
=
newLineCount
-
lineCount
-
cnt
+
spliceLineNumber
+
1
;
let
newLines
:
string
[]
=
[];
for
(
let
i
=
0
;
i
<
cnt
;
i
++
)
{
let
lineNumber
=
fromLineNumber
+
i
;
newLines
[
lineNumber
-
fromLineNumber
]
=
this
.
getLineContent
(
lineNumber
);
}
rawContentChanges
.
push
(
new
ModelRawLinesInserted
(
spliceLineNumber
+
1
,
startLineNumber
+
insertingLinesCnt
,
newLines
));
}
lineCount
+=
changeLineCountDelta
;
}
this
.
_increaseVersionId
();
...
...
src/vs/editor/common/viewModel/splitLinesCollection.ts
浏览文件 @
5507f635
...
...
@@ -403,6 +403,7 @@ export class SplitLinesCollection implements IViewModelLinesCollection {
insertPrefixSumValues
[
i
]
=
outputLineCount
;
}
// TODO@Alex: use arrays.arrayInsert
this
.
lines
=
this
.
lines
.
slice
(
0
,
fromLineNumber
-
1
).
concat
(
insertLines
).
concat
(
this
.
lines
.
slice
(
fromLineNumber
-
1
));
this
.
prefixSumComputer
.
insertValues
(
fromLineNumber
-
1
,
insertPrefixSumValues
);
...
...
src/vs/editor/test/common/model/model.test.ts
浏览文件 @
5507f635
...
...
@@ -129,7 +129,6 @@ suite('Editor Model - Model', () => {
thisModel
.
applyEdits
([
EditOperation
.
insert
(
new
Position
(
1
,
3
),
'
new line
\n
No longer
'
)]);
assert
.
deepEqual
(
e
,
new
ModelRawContentChangedEvent
(
[
new
ModelRawLineChanged
(
1
,
'
My new line First Line
'
),
new
ModelRawLineChanged
(
1
,
'
My new line
'
),
new
ModelRawLinesInserted
(
2
,
2
,
[
'
No longer First Line
'
]),
],
...
...
@@ -245,7 +244,6 @@ suite('Editor Model - Model', () => {
thisModel
.
applyEdits
([
EditOperation
.
delete
(
new
Range
(
1
,
4
,
2
,
6
))]);
assert
.
deepEqual
(
e
,
new
ModelRawContentChangedEvent
(
[
new
ModelRawLineChanged
(
1
,
'
My
'
),
new
ModelRawLineChanged
(
1
,
'
My Second Line
'
),
new
ModelRawLinesDeleted
(
2
,
2
),
],
...
...
@@ -266,7 +264,6 @@ suite('Editor Model - Model', () => {
thisModel
.
applyEdits
([
EditOperation
.
delete
(
new
Range
(
1
,
4
,
3
,
5
))]);
assert
.
deepEqual
(
e
,
new
ModelRawContentChangedEvent
(
[
new
ModelRawLineChanged
(
1
,
'
My
'
),
new
ModelRawLineChanged
(
1
,
'
My Third Line
'
),
new
ModelRawLinesDeleted
(
2
,
3
),
],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录