Skip to content

Commit 1127800

Browse files
authored
Merge pull request microsoft#62667 from YisraelV/deleteCommand
fix microsoft#62112 - merge overlapping delete operations
2 parents 98b8fdf + f6aef92 commit 1127800

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/vs/editor/contrib/linesOperations/linesOperations.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ interface IDeleteLinesOperation {
270270
positionColumn: number;
271271
}
272272

273-
class DeleteLinesAction extends EditorAction {
273+
export class DeleteLinesAction extends EditorAction {
274274

275275
constructor() {
276276
super({
@@ -322,14 +322,17 @@ class DeleteLinesAction extends EditorAction {
322322

323323
// Sort delete operations
324324
operations.sort((a, b) => {
325+
if (a.startLineNumber === b.startLineNumber) {
326+
return a.endLineNumber - b.endLineNumber;
327+
}
325328
return a.startLineNumber - b.startLineNumber;
326329
});
327330

328-
// Merge delete operations on consecutive lines
331+
// Merge delete operations which are adjacent or overlapping
329332
let mergedOperations: IDeleteLinesOperation[] = [];
330333
let previousOperation = operations[0];
331334
for (let i = 1; i < operations.length; i++) {
332-
if (previousOperation.endLineNumber + 1 === operations[i].startLineNumber) {
335+
if (previousOperation.endLineNumber + 1 >= operations[i].startLineNumber) {
333336
// Merge current operations into the previous one
334337
previousOperation.endLineNumber = operations[i].endLineNumber;
335338
} else {

src/vs/editor/contrib/linesOperations/test/linesOperations.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Position } from 'vs/editor/common/core/position';
99
import { Selection } from 'vs/editor/common/core/selection';
1010
import { Handler } from 'vs/editor/common/editorCommon';
1111
import { ITextModel } from 'vs/editor/common/model';
12-
import { DeleteAllLeftAction, DeleteAllRightAction, IndentLinesAction, InsertLineAfterAction, InsertLineBeforeAction, JoinLinesAction, LowerCaseAction, SortLinesAscendingAction, SortLinesDescendingAction, TransposeAction, UpperCaseAction } from 'vs/editor/contrib/linesOperations/linesOperations';
12+
import { DeleteAllLeftAction, DeleteAllRightAction, IndentLinesAction, InsertLineAfterAction, InsertLineBeforeAction, JoinLinesAction, LowerCaseAction, SortLinesAscendingAction, SortLinesDescendingAction, TransposeAction, UpperCaseAction, DeleteLinesAction } from 'vs/editor/contrib/linesOperations/linesOperations';
1313
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
1414
import { createTextModel } from 'vs/editor/test/common/editorTestUtils';
1515

@@ -879,4 +879,24 @@ suite('Editor Contrib - Line Operations', () => {
879879

880880
model.dispose();
881881
});
882+
883+
test('issue #62112: Delete line does not work properly when multiple cursors are on line', () => {
884+
const TEXT = [
885+
'a',
886+
'foo boo',
887+
'too',
888+
'c',
889+
];
890+
withTestCodeEditor(TEXT, {}, (editor, cursor) => {
891+
editor.setSelections([
892+
new Selection(2, 4, 2, 4),
893+
new Selection(2, 8, 2, 8),
894+
new Selection(3, 4, 3, 4),
895+
]);
896+
const deleteLinesAction = new DeleteLinesAction();
897+
deleteLinesAction.run(null, editor);
898+
899+
assert.equal(editor.getValue(), 'a\nc');
900+
});
901+
});
882902
});

0 commit comments

Comments
 (0)