提交 3929ea09 编写于 作者: A Alex Dima

Fixes #48741: Sort reverse edit operations only if order is not significant

上级 b1f5a4d5
......@@ -206,13 +206,17 @@ 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.isBefore(rangeEnd)) {
// overlapping ranges
throw new Error('Overlapping ranges are not allowed!');
if (nextRangeStart.isBeforeOrEqual(rangeEnd)) {
if (nextRangeStart.isBefore(rangeEnd)) {
// overlapping ranges
throw new Error('Overlapping ranges are not allowed!');
}
hasTouchingRanges = true;
}
}
......@@ -256,7 +260,11 @@ export class PieceTreeTextBuffer implements ITextBuffer {
forceMoveMarkers: op.forceMoveMarkers
};
}
reverseOperations.sort((a, b) => a.sortIndex - b.sortIndex);
// Can only sort reverse operations when the order is not significant
if (!hasTouchingRanges) {
reverseOperations.sort((a, b) => a.sortIndex - b.sortIndex);
}
this._mightContainRTL = mightContainRTL;
this._mightContainNonBasicASCII = mightContainNonBasicASCII;
......
......@@ -1091,4 +1091,26 @@ suite('EditorModel - EditableTextModel.applyEdits', () => {
model.dispose();
});
test('issue #48741: Broken undo stack with move lines up with multiple cursors', () => {
let model = createEditableTextModelFromString([
'line1',
'line2',
'line3',
'',
].join('\n'));
const undoEdits = model.applyEdits([
{ range: new Range(4, 1, 4, 1), text: 'line3', },
{ 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: '\nline2' }
]);
model.applyEdits(undoEdits);
assert.deepEqual(model.getValue(), 'line1\nline2\nline3\n');
model.dispose();
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册