Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
aa66fbf2
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,发现更多精彩内容 >>
未验证
提交
aa66fbf2
编写于
3月 19, 2020
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid computing undo edits if not necessary
上级
f4f93a67
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
41 addition
and
32 deletion
+41
-32
src/vs/editor/common/model.ts
src/vs/editor/common/model.ts
+5
-3
src/vs/editor/common/model/editStack.ts
src/vs/editor/common/model/editStack.ts
+1
-1
src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.ts
...r/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.ts
+16
-15
src/vs/editor/common/model/textModel.ts
src/vs/editor/common/model/textModel.ts
+8
-4
src/vs/editor/test/common/model/editableTextModel.test.ts
src/vs/editor/test/common/model/editableTextModel.test.ts
+1
-1
src/vs/editor/test/common/model/editableTextModelTestUtils.ts
...vs/editor/test/common/model/editableTextModelTestUtils.ts
+2
-2
src/vs/editor/test/common/model/model.test.ts
src/vs/editor/test/common/model/model.test.ts
+1
-1
src/vs/editor/test/common/model/modelEditOperation.test.ts
src/vs/editor/test/common/model/modelEditOperation.test.ts
+2
-2
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+4
-2
src/vs/workbench/contrib/bulkEdit/browser/bulkEditPreview.ts
src/vs/workbench/contrib/bulkEdit/browser/bulkEditPreview.ts
+1
-1
未找到文件。
src/vs/editor/common/model.ts
浏览文件 @
aa66fbf2
...
...
@@ -1092,9 +1092,11 @@ export interface ITextModel {
* Edit the model without adding the edits to the undo stack.
* This can have dire consequences on the undo stack! See @pushEditOperations for the preferred way.
* @param operations The edit operations.
* @return
T
he inverse edit operations, that, when applied, will bring the model back to the previous state.
* @return
If desired, t
he inverse edit operations, that, when applied, will bring the model back to the previous state.
*/
applyEdits
(
operations
:
IIdentifiedSingleEditOperation
[]):
IValidEditOperation
[];
applyEdits
(
operations
:
IIdentifiedSingleEditOperation
[]):
void
;
applyEdits
(
operations
:
IIdentifiedSingleEditOperation
[],
computeUndoEdits
:
false
):
void
;
applyEdits
(
operations
:
IIdentifiedSingleEditOperation
[],
computeUndoEdits
:
true
):
IValidEditOperation
[];
/**
* Change the end of line sequence without recording in the undo stack.
...
...
@@ -1299,7 +1301,7 @@ export interface ITextBuffer {
export
class
ApplyEditsResult
{
constructor
(
public
readonly
reverseEdits
:
IValidEditOperation
[],
public
readonly
reverseEdits
:
IValidEditOperation
[]
|
null
,
public
readonly
changes
:
IInternalModelContentChange
[],
public
readonly
trimAutoWhitespaceLineNumbers
:
number
[]
|
null
)
{
}
...
...
src/vs/editor/common/model/editStack.ts
浏览文件 @
aa66fbf2
...
...
@@ -326,7 +326,7 @@ export class EditStack {
public
pushEditOperation
(
beforeCursorState
:
Selection
[]
|
null
,
editOperations
:
IIdentifiedSingleEditOperation
[],
cursorStateComputer
:
ICursorStateComputer
|
null
):
Selection
[]
|
null
{
const
editStackElement
=
this
.
_getOrCreateEditStackElement
(
beforeCursorState
);
const
inverseEditOperations
=
this
.
_model
.
applyEdits
(
editOperations
);
const
inverseEditOperations
=
this
.
_model
.
applyEdits
(
editOperations
,
true
);
const
afterCursorState
=
EditStack
.
_computeCursorState
(
cursorStateComputer
,
inverseEditOperations
);
editStackElement
.
append
(
this
.
_model
,
inverseEditOperations
,
getModelEOL
(
this
.
_model
),
this
.
_model
.
getAlternativeVersionId
(),
afterCursorState
);
return
afterCursorState
;
...
...
src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.ts
浏览文件 @
aa66fbf2
...
...
@@ -261,6 +261,20 @@ export class PieceTreeTextBuffer implements ITextBuffer {
// Sort operations ascending
operations
.
sort
(
PieceTreeTextBuffer
.
_sortOpsAscending
);
let
hasTouchingRanges
=
false
;
for
(
let
i
=
0
,
count
=
operations
.
length
-
1
;
i
<
count
;
i
++
)
{
let
rangeEnd
=
operations
[
i
].
range
.
getEndPosition
();
let
nextRangeStart
=
operations
[
i
+
1
].
range
.
getStartPosition
();
if
(
nextRangeStart
.
isBeforeOrEqual
(
rangeEnd
))
{
if
(
nextRangeStart
.
isBefore
(
rangeEnd
))
{
// overlapping ranges
throw
new
Error
(
'
Overlapping ranges are not allowed!
'
);
}
hasTouchingRanges
=
true
;
}
}
if
(
canReduceOperations
)
{
operations
=
this
.
_reduceOperations
(
operations
);
}
...
...
@@ -289,24 +303,11 @@ export class PieceTreeTextBuffer implements ITextBuffer {
}
}
let
reverseOperations
:
IReverseSingleEditOperation
[]
=
[]
;
let
reverseOperations
:
IReverseSingleEditOperation
[]
|
null
=
null
;
if
(
computeUndoEdits
)
{
let
hasTouchingRanges
=
false
;
for
(
let
i
=
0
,
count
=
operations
.
length
-
1
;
i
<
count
;
i
++
)
{
let
rangeEnd
=
operations
[
i
].
range
.
getEndPosition
();
let
nextRangeStart
=
operations
[
i
+
1
].
range
.
getStartPosition
();
if
(
nextRangeStart
.
isBeforeOrEqual
(
rangeEnd
))
{
if
(
nextRangeStart
.
isBefore
(
rangeEnd
))
{
// overlapping ranges
throw
new
Error
(
'
Overlapping ranges are not allowed!
'
);
}
hasTouchingRanges
=
true
;
}
}
let
reverseRangeDeltaOffset
=
0
;
reverseOperations
=
[];
for
(
let
i
=
0
;
i
<
operations
.
length
;
i
++
)
{
const
op
=
operations
[
i
];
const
reverseRange
=
reverseRanges
[
i
];
...
...
src/vs/editor/common/model/textModel.ts
浏览文件 @
aa66fbf2
...
...
@@ -1330,18 +1330,22 @@ export class TextModel extends Disposable implements model.ITextModel {
}
}
public
applyEdits
(
rawOperations
:
model
.
IIdentifiedSingleEditOperation
[],
computeUndoEdits
:
boolean
=
true
):
model
.
IValidEditOperation
[]
{
public
applyEdits
(
operations
:
model
.
IIdentifiedSingleEditOperation
[]):
void
;
public
applyEdits
(
operations
:
model
.
IIdentifiedSingleEditOperation
[],
computeUndoEdits
:
false
):
void
;
public
applyEdits
(
operations
:
model
.
IIdentifiedSingleEditOperation
[],
computeUndoEdits
:
true
):
model
.
IValidEditOperation
[];
public
applyEdits
(
rawOperations
:
model
.
IIdentifiedSingleEditOperation
[],
computeUndoEdits
:
boolean
=
false
):
void
|
model
.
IValidEditOperation
[]
{
try
{
this
.
_onDidChangeDecorations
.
beginDeferredEmit
();
this
.
_eventEmitter
.
beginDeferredEmit
();
return
this
.
_doApplyEdits
(
this
.
_validateEditOperations
(
rawOperations
),
computeUndoEdits
);
const
operations
=
this
.
_validateEditOperations
(
rawOperations
);
return
this
.
_doApplyEdits
(
operations
,
computeUndoEdits
);
}
finally
{
this
.
_eventEmitter
.
endDeferredEmit
();
this
.
_onDidChangeDecorations
.
endDeferredEmit
();
}
}
private
_doApplyEdits
(
rawOperations
:
model
.
ValidAnnotatedEditOperation
[],
computeUndoEdits
:
boolean
):
model
.
IValidEditOperation
[]
{
private
_doApplyEdits
(
rawOperations
:
model
.
ValidAnnotatedEditOperation
[],
computeUndoEdits
:
boolean
):
void
|
model
.
IValidEditOperation
[]
{
const
oldLineCount
=
this
.
_buffer
.
getLineCount
();
const
result
=
this
.
_buffer
.
applyEdits
(
rawOperations
,
this
.
_options
.
trimAutoWhitespace
,
computeUndoEdits
);
...
...
@@ -1419,7 +1423,7 @@ export class TextModel extends Disposable implements model.ITextModel {
);
}
return
result
.
reverseEdits
;
return
(
result
.
reverseEdits
===
null
?
undefined
:
result
.
reverseEdits
)
;
}
public
undo
():
void
{
...
...
src/vs/editor/test/common/model/editableTextModel.test.ts
浏览文件 @
aa66fbf2
...
...
@@ -1104,7 +1104,7 @@ suite('EditorModel - EditableTextModel.applyEdits', () => {
{
range
:
new
Range
(
3
,
1
,
3
,
6
),
text
:
null
,
},
{
range
:
new
Range
(
2
,
1
,
3
,
1
),
text
:
null
,
},
{
range
:
new
Range
(
3
,
6
,
3
,
6
),
text
:
'
\n
line2
'
}
]);
]
,
true
);
model
.
applyEdits
(
undoEdits
);
...
...
src/vs/editor/test/common/model/editableTextModelTestUtils.ts
浏览文件 @
aa66fbf2
...
...
@@ -17,7 +17,7 @@ export function testApplyEditsWithSyncedModels(original: string[], edits: IIdent
assertSyncedModels
(
originalStr
,
(
model
,
assertMirrorModels
)
=>
{
// Apply edits & collect inverse edits
let
inverseEdits
=
model
.
applyEdits
(
edits
);
let
inverseEdits
=
model
.
applyEdits
(
edits
,
true
);
// Assert edits produced expected result
assert
.
deepEqual
(
model
.
getValue
(
EndOfLinePreference
.
LF
),
expectedStr
);
...
...
@@ -25,7 +25,7 @@ export function testApplyEditsWithSyncedModels(original: string[], edits: IIdent
assertMirrorModels
();
// Apply the inverse edits
let
inverseInverseEdits
=
model
.
applyEdits
(
inverseEdits
);
let
inverseInverseEdits
=
model
.
applyEdits
(
inverseEdits
,
true
);
// Assert the inverse edits brought back model to original state
assert
.
deepEqual
(
model
.
getValue
(
EndOfLinePreference
.
LF
),
originalStr
);
...
...
src/vs/editor/test/common/model/model.test.ts
浏览文件 @
aa66fbf2
...
...
@@ -330,7 +330,7 @@ suite('Editor Model - Model', () => {
let
res
=
thisModel
.
applyEdits
([
{
range
:
new
Range
(
2
,
1
,
2
,
1
),
text
:
'
a
'
},
{
range
:
new
Range
(
1
,
1
,
1
,
1
),
text
:
'
b
'
},
]);
]
,
true
);
assert
.
deepEqual
(
res
[
0
].
range
,
new
Range
(
2
,
1
,
2
,
2
));
assert
.
deepEqual
(
res
[
1
].
range
,
new
Range
(
1
,
1
,
1
,
2
));
...
...
src/vs/editor/test/common/model/modelEditOperation.test.ts
浏览文件 @
aa66fbf2
...
...
@@ -50,14 +50,14 @@ suite('Editor Model - Model Edit Operation', () => {
function
assertSingleEditOp
(
singleEditOp
:
IIdentifiedSingleEditOperation
,
editedLines
:
string
[])
{
let
editOp
=
[
singleEditOp
];
let
inverseEditOp
=
model
.
applyEdits
(
editOp
);
let
inverseEditOp
=
model
.
applyEdits
(
editOp
,
true
);
assert
.
equal
(
model
.
getLineCount
(),
editedLines
.
length
);
for
(
let
i
=
0
;
i
<
editedLines
.
length
;
i
++
)
{
assert
.
equal
(
model
.
getLineContent
(
i
+
1
),
editedLines
[
i
]);
}
let
originalOp
=
model
.
applyEdits
(
inverseEditOp
);
let
originalOp
=
model
.
applyEdits
(
inverseEditOp
,
true
);
assert
.
equal
(
model
.
getLineCount
(),
5
);
assert
.
equal
(
model
.
getLineContent
(
1
),
LINE1
);
...
...
src/vs/monaco.d.ts
浏览文件 @
aa66fbf2
...
...
@@ -1902,9 +1902,11 @@ declare namespace monaco.editor {
* Edit the model without adding the edits to the undo stack.
* This can have dire consequences on the undo stack! See @pushEditOperations for the preferred way.
* @param operations The edit operations.
* @return
T
he inverse edit operations, that, when applied, will bring the model back to the previous state.
* @return
If desired, t
he inverse edit operations, that, when applied, will bring the model back to the previous state.
*/
applyEdits
(
operations
:
IIdentifiedSingleEditOperation
[]):
IValidEditOperation
[];
applyEdits
(
operations
:
IIdentifiedSingleEditOperation
[]):
void
;
applyEdits
(
operations
:
IIdentifiedSingleEditOperation
[],
computeUndoEdits
:
false
):
void
;
applyEdits
(
operations
:
IIdentifiedSingleEditOperation
[],
computeUndoEdits
:
true
):
IValidEditOperation
[];
/**
* Change the end of line sequence without recording in the undo stack.
* This can have dire consequences on the undo stack! See @pushEOL for the preferred way.
...
...
src/vs/workbench/contrib/bulkEdit/browser/bulkEditPreview.ts
浏览文件 @
aa66fbf2
...
...
@@ -399,7 +399,7 @@ export class BulkEditPreviewProvider implements ITextModelContentProvider {
}
// apply new edits and keep (future) undo edits
const
newEdits
=
this
.
_operations
.
getFileEdits
(
uri
);
const
newUndoEdits
=
model
.
applyEdits
(
newEdits
);
const
newUndoEdits
=
model
.
applyEdits
(
newEdits
,
true
);
this
.
_modelPreviewEdits
.
set
(
model
.
id
,
newUndoEdits
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录