mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
Fixes #48741: Sort reverse edit operations only if order is not significant
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user