Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
cf05245d
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,发现更多精彩内容 >>
提交
cf05245d
编写于
1月 03, 2018
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce ITextBuffer
上级
23e64652
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
46 addition
and
42 deletion
+46
-42
src/vs/editor/common/model/editableTextModel.ts
src/vs/editor/common/model/editableTextModel.ts
+1
-1
src/vs/editor/common/model/indentationGuesser.ts
src/vs/editor/common/model/indentationGuesser.ts
+2
-2
src/vs/editor/common/model/modelLine.ts
src/vs/editor/common/model/modelLine.ts
+4
-4
src/vs/editor/common/model/textBuffer.ts
src/vs/editor/common/model/textBuffer.ts
+36
-32
src/vs/editor/common/model/textModel.ts
src/vs/editor/common/model/textModel.ts
+3
-3
未找到文件。
src/vs/editor/common/model/editableTextModel.ts
浏览文件 @
cf05245d
...
...
@@ -170,7 +170,7 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
for
(
let
i
=
0
,
len
=
rawOperations
.
length
;
i
<
len
;
i
++
)
{
rawOperations
[
i
].
range
=
this
.
validateRange
(
rawOperations
[
i
].
range
);
}
const
result
=
this
.
_buffer
.
_
applyEdits
(
rawOperations
,
this
.
_options
.
trimAutoWhitespace
);
const
result
=
this
.
_buffer
.
applyEdits
(
rawOperations
,
this
.
_options
.
trimAutoWhitespace
);
const
rawContentChanges
=
result
.
rawChanges
;
const
contentChanges
=
result
.
changes
;
this
.
_trimAutoWhitespaceLines
=
result
.
trimAutoWhitespaceLineNumbers
;
...
...
src/vs/editor/common/model/indentationGuesser.ts
浏览文件 @
cf05245d
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
import
{
TextBuffer
}
from
'
vs/editor/common/model/textBuffer
'
;
import
{
I
TextBuffer
}
from
'
vs/editor/common/model/textBuffer
'
;
export
interface
IIndentationGuesserTarget
{
getLineCount
():
number
;
...
...
@@ -15,7 +15,7 @@ export interface IIndentationGuesserTarget {
export
class
IndentationGuesserTextBufferTarget
implements
IIndentationGuesserTarget
{
constructor
(
private
readonly
_buffer
:
TextBuffer
private
readonly
_buffer
:
I
TextBuffer
)
{
}
public
getLineCount
():
number
{
...
...
src/vs/editor/common/model/modelLine.ts
浏览文件 @
cf05245d
...
...
@@ -12,7 +12,7 @@ import { Position } from 'vs/editor/common/core/position';
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IModelTokensChangedEvent
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
TextBuffer
}
from
'
vs/editor/common/model/textBuffer
'
;
import
{
I
TextBuffer
}
from
'
vs/editor/common/model/textBuffer
'
;
import
{
TokenizationResult2
}
from
'
vs/editor/common/core/token
'
;
import
{
nullTokenize2
}
from
'
vs/editor/common/modes/nullMode
'
;
...
...
@@ -247,7 +247,7 @@ export class ModelLinesTokens {
return
(
firstInvalidLineNumber
>=
lineNumber
);
}
public
hasLinesToTokenize
(
buffer
:
TextBuffer
):
boolean
{
public
hasLinesToTokenize
(
buffer
:
I
TextBuffer
):
boolean
{
return
(
this
.
_invalidLineStartIndex
<
buffer
.
getLineCount
());
}
...
...
@@ -413,7 +413,7 @@ export class ModelLinesTokens {
//#region Tokenization
public
_tokenizeOneLine
(
buffer
:
TextBuffer
,
eventBuilder
:
ModelTokensChangedEventBuilder
):
number
{
public
_tokenizeOneLine
(
buffer
:
I
TextBuffer
,
eventBuilder
:
ModelTokensChangedEventBuilder
):
number
{
if
(
!
this
.
hasLinesToTokenize
(
buffer
))
{
return
buffer
.
getLineCount
()
+
1
;
}
...
...
@@ -422,7 +422,7 @@ export class ModelLinesTokens {
return
lineNumber
;
}
public
_updateTokensUntilLine
(
buffer
:
TextBuffer
,
eventBuilder
:
ModelTokensChangedEventBuilder
,
lineNumber
:
number
):
void
{
public
_updateTokensUntilLine
(
buffer
:
I
TextBuffer
,
eventBuilder
:
ModelTokensChangedEventBuilder
,
lineNumber
:
number
):
void
{
if
(
!
this
.
tokenizationSupport
)
{
this
.
_invalidLineStartIndex
=
buffer
.
getLineCount
();
return
;
...
...
src/vs/editor/common/model/textBuffer.ts
浏览文件 @
cf05245d
...
...
@@ -15,12 +15,31 @@ import { IValidatedEditOperation } from 'vs/editor/common/model/editableTextMode
import
{
ModelRawChange
,
IModelContentChange
,
ModelRawLineChanged
,
ModelRawLinesDeleted
,
ModelRawLinesInserted
}
from
'
vs/editor/common/model/textModelEvents
'
;
export
interface
ITextBuffer
{
equals
(
other
:
ITextSource
):
boolean
;
mightContainRTL
():
boolean
;
mightContainNonBasicASCII
():
boolean
;
getBOM
():
string
;
getEOL
():
string
;
getOffsetAt
(
lineNumber
:
number
,
column
:
number
):
number
;
getPositionAt
(
offset
:
number
):
Position
;
getRangeAt
(
offset
:
number
,
length
:
number
):
Range
;
getValueInRange
(
range
:
Range
,
eol
:
editorCommon
.
EndOfLinePreference
):
string
;
getValueLengthInRange
(
range
:
Range
,
eol
:
editorCommon
.
EndOfLinePreference
):
number
;
getLineCount
():
number
;
getLinesContent
():
string
[];
getLineContent
(
lineNumber
:
number
):
string
;
getLineCharCode
(
lineNumber
:
number
,
index
:
number
):
number
;
getLineLength
(
lineNumber
:
number
):
number
;
getLineFirstNonWhitespaceColumn
(
lineNumber
:
number
):
number
;
getLineLastNonWhitespaceColumn
(
lineNumber
:
number
):
number
;
setEOL
(
newEOL
:
string
):
void
;
applyEdits
(
rawOperations
:
editorCommon
.
IIdentifiedSingleEditOperation
[],
recordTrimAutoWhitespace
:
boolean
):
ApplyEditsResult
;
}
export
class
ApplyEditResult
{
export
class
ApplyEdit
s
Result
{
constructor
(
public
readonly
reverseEdits
:
editorCommon
.
IIdentifiedSingleEditOperation
[],
...
...
@@ -38,7 +57,7 @@ export interface IInternalModelContentChange extends IModelContentChange {
forceMoveMarkers
:
boolean
;
}
export
class
TextBuffer
{
export
class
TextBuffer
implements
ITextBuffer
{
private
_lines
:
string
[];
private
_BOM
:
string
;
...
...
@@ -140,7 +159,7 @@ export class TextBuffer {
throw
new
Error
(
'
Unknown EOL preference
'
);
}
public
getValueInRange
(
range
:
Range
,
eol
:
editorCommon
.
EndOfLinePreference
=
editorCommon
.
EndOfLinePreference
.
TextDefined
):
string
{
public
getValueInRange
(
range
:
Range
,
eol
:
editorCommon
.
EndOfLinePreference
):
string
{
if
(
range
.
isEmpty
())
{
return
''
;
}
...
...
@@ -163,7 +182,7 @@ export class TextBuffer {
return
resultLines
.
join
(
lineEnding
);
}
public
getValueLengthInRange
(
range
:
Range
,
eol
:
editorCommon
.
EndOfLinePreference
=
editorCommon
.
EndOfLinePreference
.
TextDefined
):
number
{
public
getValueLengthInRange
(
range
:
Range
,
eol
:
editorCommon
.
EndOfLinePreference
):
number
{
if
(
range
.
isEmpty
())
{
return
0
;
}
...
...
@@ -197,14 +216,6 @@ export class TextBuffer {
return
this
.
_lines
[
lineNumber
-
1
].
length
;
}
public
getLineMinColumn
(
lineNumber
:
number
):
number
{
return
1
;
}
public
getLineMaxColumn
(
lineNumber
:
number
):
number
{
return
this
.
_lines
[
lineNumber
-
1
].
length
+
1
;
}
public
getLineFirstNonWhitespaceColumn
(
lineNumber
:
number
):
number
{
const
result
=
strings
.
firstNonWhitespaceIndex
(
this
.
_lines
[
lineNumber
-
1
]);
if
(
result
===
-
1
)
{
...
...
@@ -244,9 +255,9 @@ export class TextBuffer {
return
-
r
;
}
public
_applyEdits
(
rawOperations
:
editorCommon
.
IIdentifiedSingleEditOperation
[],
recordTrimAutoWhitespace
:
boolean
):
ApplyEdit
Result
{
public
applyEdits
(
rawOperations
:
editorCommon
.
IIdentifiedSingleEditOperation
[],
recordTrimAutoWhitespace
:
boolean
):
ApplyEdits
Result
{
if
(
rawOperations
.
length
===
0
)
{
return
new
ApplyEditResult
([],
[],
[],
[]);
return
new
ApplyEdit
s
Result
([],
[],
[],
[]);
}
let
mightContainRTL
=
this
.
_mightContainRTL
;
...
...
@@ -272,7 +283,7 @@ export class TextBuffer {
identifier
:
op
.
identifier
,
range
:
validatedRange
,
rangeOffset
:
this
.
getOffsetAt
(
validatedRange
.
startLineNumber
,
validatedRange
.
startColumn
),
rangeLength
:
this
.
getValueLengthInRange
(
validatedRange
),
rangeLength
:
this
.
getValueLengthInRange
(
validatedRange
,
editorCommon
.
EndOfLinePreference
.
TextDefined
),
lines
:
op
.
text
?
op
.
text
.
split
(
/
\r\n
|
\r
|
\n
/
)
:
null
,
forceMoveMarkers
:
op
.
forceMoveMarkers
,
isAutoWhitespaceEdit
:
op
.
isAutoWhitespaceEdit
||
false
...
...
@@ -327,7 +338,7 @@ export class TextBuffer {
reverseOperations
[
i
]
=
{
identifier
:
op
.
identifier
,
range
:
reverseRange
,
text
:
this
.
getValueInRange
(
op
.
range
),
text
:
this
.
getValueInRange
(
op
.
range
,
editorCommon
.
EndOfLinePreference
.
TextDefined
),
forceMoveMarkers
:
op
.
forceMoveMarkers
};
}
...
...
@@ -361,7 +372,7 @@ export class TextBuffer {
}
}
return
new
ApplyEditResult
(
return
new
ApplyEdit
s
Result
(
reverseOperations
,
rawContentChanges
,
contentChanges
,
...
...
@@ -438,7 +449,7 @@ export class TextBuffer {
identifier
:
operations
[
0
].
identifier
,
range
:
entireEditRange
,
rangeOffset
:
this
.
getOffsetAt
(
entireEditRange
.
startLineNumber
,
entireEditRange
.
startColumn
),
rangeLength
:
this
.
getValueLengthInRange
(
entireEditRange
),
rangeLength
:
this
.
getValueLengthInRange
(
entireEditRange
,
editorCommon
.
EndOfLinePreference
.
TextDefined
),
lines
:
result
.
join
(
''
).
split
(
'
\n
'
),
forceMoveMarkers
:
forceMoveMarkers
,
isAutoWhitespaceEdit
:
false
...
...
@@ -448,9 +459,7 @@ export class TextBuffer {
private
_setLineContent
(
lineNumber
:
number
,
content
:
string
,
rawContentChanges
:
ModelRawChange
[]):
void
{
this
.
_lines
[
lineNumber
-
1
]
=
content
;
this
.
_lineStarts
.
changeValue
(
lineNumber
-
1
,
content
.
length
+
this
.
_EOL
.
length
);
rawContentChanges
.
push
(
new
ModelRawLineChanged
(
lineNumber
,
content
)
);
rawContentChanges
.
push
(
new
ModelRawLineChanged
(
lineNumber
,
content
));
}
private
_doApplyEdits
(
operations
:
IValidatedEditOperation
[]):
[
ModelRawChange
[],
IInternalModelContentChange
[]]
{
...
...
@@ -484,7 +493,7 @@ export class TextBuffer {
if
(
editLineNumber
===
startLineNumber
||
editLineNumber
===
endLineNumber
)
{
const
editStartColumn
=
(
editLineNumber
===
startLineNumber
?
startColumn
:
1
);
const
editEndColumn
=
(
editLineNumber
===
endLineNumber
?
endColumn
:
this
.
getLine
MaxColumn
(
editLineNumber
)
);
const
editEndColumn
=
(
editLineNumber
===
endLineNumber
?
endColumn
:
this
.
getLine
Length
(
editLineNumber
)
+
1
);
editText
=
(
this
.
_lines
[
editLineNumber
-
1
].
substring
(
0
,
editStartColumn
-
1
)
...
...
@@ -502,15 +511,13 @@ export class TextBuffer {
const
spliceStartLineNumber
=
startLineNumber
+
editingLinesCnt
;
const
endLineRemains
=
this
.
_lines
[
endLineNumber
-
1
].
substring
(
endColumn
-
1
);
this
.
_lines
.
splice
(
spliceStartLineNumber
,
endLineNumber
-
spliceStartLineNumber
);
this
.
_lineStarts
.
removeValues
(
spliceStartLineNumber
,
endLineNumber
-
spliceStartLineNumber
);
// Reconstruct first line
this
.
_setLineContent
(
spliceStartLineNumber
,
this
.
_lines
[
spliceStartLineNumber
-
1
]
+
endLineRemains
,
rawContentChanges
);
rawContentChanges
.
push
(
new
ModelRawLinesDeleted
(
spliceStartLineNumber
+
1
,
endLineNumber
)
);
this
.
_lines
.
splice
(
spliceStartLineNumber
,
endLineNumber
-
spliceStartLineNumber
);
this
.
_lineStarts
.
removeValues
(
spliceStartLineNumber
,
endLineNumber
-
spliceStartLineNumber
);
rawContentChanges
.
push
(
new
ModelRawLinesDeleted
(
spliceStartLineNumber
+
1
,
endLineNumber
));
}
if
(
editingLinesCnt
<
insertingLinesCnt
)
{
...
...
@@ -539,9 +546,7 @@ export class TextBuffer {
this
.
_lines
=
arrays
.
arrayInsert
(
this
.
_lines
,
startLineNumber
+
editingLinesCnt
,
newLines
);
this
.
_lineStarts
.
insertValues
(
startLineNumber
+
editingLinesCnt
,
newLinesLengths
);
rawContentChanges
.
push
(
new
ModelRawLinesInserted
(
spliceLineNumber
+
1
,
startLineNumber
+
insertingLinesCnt
,
newLines
)
);
rawContentChanges
.
push
(
new
ModelRawLinesInserted
(
spliceLineNumber
+
1
,
startLineNumber
+
insertingLinesCnt
,
newLines
));
}
const
contentChangeRange
=
new
Range
(
startLineNumber
,
startColumn
,
endLineNumber
,
endColumn
);
...
...
@@ -559,7 +564,6 @@ export class TextBuffer {
return
[
rawContentChanges
,
contentChanges
];
}
/**
* Assumes `operations` are validated and sorted ascending
*/
...
...
src/vs/editor/common/model/textModel.ts
浏览文件 @
cf05245d
...
...
@@ -16,7 +16,7 @@ import { TextModelSearch, SearchParams } from 'vs/editor/common/model/textModelS
import
{
TextSource
,
ITextSource
,
IRawTextSource
,
RawTextSource
}
from
'
vs/editor/common/model/textSource
'
;
import
{
IModelContentChangedEvent
,
ModelRawContentChangedEvent
,
ModelRawFlush
,
ModelRawEOLChanged
,
IModelOptionsChangedEvent
,
InternalModelContentChangeEvent
}
from
'
vs/editor/common/model/textModelEvents
'
;
import
{
Disposable
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
TextBuffer
}
from
'
vs/editor/common/model/textBuffer
'
;
import
{
TextBuffer
,
ITextBuffer
}
from
'
vs/editor/common/model/textBuffer
'
;
const
LIMIT_FIND_COUNT
=
999
;
export
const
LONG_LINE_BOUNDARY
=
10000
;
...
...
@@ -95,7 +95,7 @@ export class TextModel extends Disposable implements editorCommon.ITextModel {
private
readonly
_shouldSimplifyMode
:
boolean
;
protected
readonly
_isTooLargeForTokenization
:
boolean
;
protected
_buffer
:
TextBuffer
;
protected
_buffer
:
I
TextBuffer
;
constructor
(
rawTextSource
:
IRawTextSource
,
creationOptions
:
editorCommon
.
ITextModelCreationOptions
)
{
super
();
...
...
@@ -467,7 +467,7 @@ export class TextModel extends Disposable implements editorCommon.ITextModel {
if
(
lineNumber
<
1
||
lineNumber
>
this
.
getLineCount
())
{
throw
new
Error
(
'
Illegal value
'
+
lineNumber
+
'
for `lineNumber`
'
);
}
return
this
.
_buffer
.
getLine
MaxColumn
(
lineNumber
)
;
return
this
.
_buffer
.
getLine
Length
(
lineNumber
)
+
1
;
}
public
getLineFirstNonWhitespaceColumn
(
lineNumber
:
number
):
number
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录