mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Merge pull request #62667 from YisraelV/deleteCommand
fix #62112 - merge overlapping delete operations
This commit is contained in:
commit
1127800a2f
|
@ -270,7 +270,7 @@ interface IDeleteLinesOperation {
|
|||
positionColumn: number;
|
||||
}
|
||||
|
||||
class DeleteLinesAction extends EditorAction {
|
||||
export class DeleteLinesAction extends EditorAction {
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
|
@ -322,14 +322,17 @@ class DeleteLinesAction extends EditorAction {
|
|||
|
||||
// Sort delete operations
|
||||
operations.sort((a, b) => {
|
||||
if (a.startLineNumber === b.startLineNumber) {
|
||||
return a.endLineNumber - b.endLineNumber;
|
||||
}
|
||||
return a.startLineNumber - b.startLineNumber;
|
||||
});
|
||||
|
||||
// Merge delete operations on consecutive lines
|
||||
// Merge delete operations which are adjacent or overlapping
|
||||
let mergedOperations: IDeleteLinesOperation[] = [];
|
||||
let previousOperation = operations[0];
|
||||
for (let i = 1; i < operations.length; i++) {
|
||||
if (previousOperation.endLineNumber + 1 === operations[i].startLineNumber) {
|
||||
if (previousOperation.endLineNumber + 1 >= operations[i].startLineNumber) {
|
||||
// Merge current operations into the previous one
|
||||
previousOperation.endLineNumber = operations[i].endLineNumber;
|
||||
} else {
|
||||
|
|
|
@ -9,7 +9,7 @@ import { Position } from 'vs/editor/common/core/position';
|
|||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { Handler } from 'vs/editor/common/editorCommon';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { DeleteAllLeftAction, DeleteAllRightAction, IndentLinesAction, InsertLineAfterAction, InsertLineBeforeAction, JoinLinesAction, LowerCaseAction, SortLinesAscendingAction, SortLinesDescendingAction, TransposeAction, UpperCaseAction } from 'vs/editor/contrib/linesOperations/linesOperations';
|
||||
import { DeleteAllLeftAction, DeleteAllRightAction, IndentLinesAction, InsertLineAfterAction, InsertLineBeforeAction, JoinLinesAction, LowerCaseAction, SortLinesAscendingAction, SortLinesDescendingAction, TransposeAction, UpperCaseAction, DeleteLinesAction } from 'vs/editor/contrib/linesOperations/linesOperations';
|
||||
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { createTextModel } from 'vs/editor/test/common/editorTestUtils';
|
||||
|
||||
|
@ -879,4 +879,24 @@ suite('Editor Contrib - Line Operations', () => {
|
|||
|
||||
model.dispose();
|
||||
});
|
||||
|
||||
test('issue #62112: Delete line does not work properly when multiple cursors are on line', () => {
|
||||
const TEXT = [
|
||||
'a',
|
||||
'foo boo',
|
||||
'too',
|
||||
'c',
|
||||
];
|
||||
withTestCodeEditor(TEXT, {}, (editor, cursor) => {
|
||||
editor.setSelections([
|
||||
new Selection(2, 4, 2, 4),
|
||||
new Selection(2, 8, 2, 8),
|
||||
new Selection(3, 4, 3, 4),
|
||||
]);
|
||||
const deleteLinesAction = new DeleteLinesAction();
|
||||
deleteLinesAction.run(null, editor);
|
||||
|
||||
assert.equal(editor.getValue(), 'a\nc');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue