mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Fixes #46342: Have model.applyEdits maintain order for inverse edits
This commit is contained in:
parent
42c882151f
commit
3114b0ca67
|
@ -23,6 +23,10 @@ export interface IValidatedEditOperation {
|
|||
isAutoWhitespaceEdit: boolean;
|
||||
}
|
||||
|
||||
export interface IReverseSingleEditOperation extends IIdentifiedSingleEditOperation {
|
||||
sortIndex: number;
|
||||
}
|
||||
|
||||
export class PieceTreeTextBuffer implements ITextBuffer {
|
||||
private _pieceTree: PieceTreeBase;
|
||||
private _BOM: string;
|
||||
|
@ -239,18 +243,20 @@ export class PieceTreeTextBuffer implements ITextBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
let reverseOperations: IIdentifiedSingleEditOperation[] = [];
|
||||
let reverseOperations: IReverseSingleEditOperation[] = [];
|
||||
for (let i = 0; i < operations.length; i++) {
|
||||
let op = operations[i];
|
||||
let reverseRange = reverseRanges[i];
|
||||
|
||||
reverseOperations[i] = {
|
||||
sortIndex: op.sortIndex,
|
||||
identifier: op.identifier,
|
||||
range: reverseRange,
|
||||
text: this.getValueInRange(op.range),
|
||||
forceMoveMarkers: op.forceMoveMarkers
|
||||
};
|
||||
}
|
||||
reverseOperations.sort((a, b) => a.sortIndex - b.sortIndex);
|
||||
|
||||
this._mightContainRTL = mightContainRTL;
|
||||
this._mightContainNonBasicASCII = mightContainNonBasicASCII;
|
||||
|
|
|
@ -31,8 +31,17 @@ export function testApplyEditsWithSyncedModels(original: string[], edits: IIdent
|
|||
assert.deepEqual(model.getValue(EndOfLinePreference.LF), originalStr);
|
||||
|
||||
if (!inputEditsAreInvalid) {
|
||||
const simplifyEdit = (edit: IIdentifiedSingleEditOperation) => {
|
||||
return {
|
||||
identifier: edit.identifier,
|
||||
range: edit.range,
|
||||
text: edit.text,
|
||||
forceMoveMarkers: edit.forceMoveMarkers,
|
||||
isAutoWhitespaceEdit: edit.isAutoWhitespaceEdit
|
||||
};
|
||||
};
|
||||
// Assert the inverse of the inverse edits are the original edits
|
||||
assert.deepEqual(inverseInverseEdits, edits);
|
||||
assert.deepEqual(inverseInverseEdits.map(simplifyEdit), edits.map(simplifyEdit));
|
||||
}
|
||||
|
||||
assertMirrorModels();
|
||||
|
|
|
@ -328,6 +328,16 @@ suite('Editor Model - Model', () => {
|
|||
false
|
||||
));
|
||||
});
|
||||
|
||||
test('issue #46342: Maintain edit operation order in applyEdits', () => {
|
||||
let res = thisModel.applyEdits([
|
||||
{ range: new Range(2, 1, 2, 1), text: 'a' },
|
||||
{ range: new Range(1, 1, 1, 1), text: 'b' },
|
||||
]);
|
||||
|
||||
assert.deepEqual(res[0].range, new Range(2, 1, 2, 2));
|
||||
assert.deepEqual(res[1].range, new Range(1, 1, 1, 2));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -68,7 +68,16 @@ suite('Editor Model - Model Edit Operation', () => {
|
|||
assert.equal(model.getLineContent(4), LINE4);
|
||||
assert.equal(model.getLineContent(5), LINE5);
|
||||
|
||||
assert.deepEqual(originalOp, editOp);
|
||||
const simplifyEdit = (edit: IIdentifiedSingleEditOperation) => {
|
||||
return {
|
||||
identifier: edit.identifier,
|
||||
range: edit.range,
|
||||
text: edit.text,
|
||||
forceMoveMarkers: edit.forceMoveMarkers,
|
||||
isAutoWhitespaceEdit: edit.isAutoWhitespaceEdit
|
||||
};
|
||||
};
|
||||
assert.deepEqual(originalOp.map(simplifyEdit), editOp.map(simplifyEdit));
|
||||
}
|
||||
|
||||
test('Insert inline', () => {
|
||||
|
|
Loading…
Reference in a new issue