Skip to content

Commit 076ad04

Browse files
committed
Adding testcases
1 parent cf9dcee commit 076ad04

2 files changed

Lines changed: 132 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ abstract class AbstractMoveLinesAction extends EditorAction {
243243
}
244244
}
245245

246-
class MoveLinesUpAction extends AbstractMoveLinesAction {
246+
export class MoveLinesUpAction extends AbstractMoveLinesAction {
247247
constructor() {
248248
super(false, {
249249
id: 'editor.action.moveLinesUpAction',
@@ -265,7 +265,7 @@ class MoveLinesUpAction extends AbstractMoveLinesAction {
265265
}
266266
}
267267

268-
class MoveLinesDownAction extends AbstractMoveLinesAction {
268+
export class MoveLinesDownAction extends AbstractMoveLinesAction {
269269
constructor() {
270270
super(true, {
271271
id: 'editor.action.moveLinesDownAction',

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

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Selection } from '../../../../common/core/selection.js';
1212
import { Handler } from '../../../../common/editorCommon.js';
1313
import { ITextModel } from '../../../../common/model.js';
1414
import { ViewModel } from '../../../../common/viewModel/viewModelImpl.js';
15-
import { CamelCaseAction, PascalCaseAction, DeleteAllLeftAction, DeleteAllRightAction, DeleteDuplicateLinesAction, DeleteLinesAction, IndentLinesAction, InsertLineAfterAction, InsertLineBeforeAction, JoinLinesAction, KebabCaseAction, LowerCaseAction, SnakeCaseAction, SortLinesAscendingAction, SortLinesDescendingAction, TitleCaseAction, TransposeAction, UpperCaseAction } from '../../browser/linesOperations.js';
15+
import { CamelCaseAction, PascalCaseAction, DeleteAllLeftAction, DeleteAllRightAction, DeleteDuplicateLinesAction, DeleteLinesAction, IndentLinesAction, InsertLineAfterAction, InsertLineBeforeAction, JoinLinesAction, KebabCaseAction, LowerCaseAction, SnakeCaseAction, SortLinesAscendingAction, SortLinesDescendingAction, TitleCaseAction, TransposeAction, UpperCaseAction, MoveLinesUpAction, MoveLinesDownAction } from '../../browser/linesOperations.js';
1616
import { withTestCodeEditor } from '../../../../test/browser/testCodeEditor.js';
1717
import { createTextModel } from '../../../../test/common/testTextModel.js';
1818

@@ -1640,4 +1640,133 @@ suite('Editor Contrib - Line Operations', () => {
16401640
]
16411641
);
16421642
});
1643+
1644+
suite('Issue #68694 Move consequitive lines with multiple selections', () => {
1645+
test('Move lines down', () => {
1646+
const TEXT = [
1647+
'Line 1',
1648+
'Line 2',
1649+
'Line 3',
1650+
'Line 4',
1651+
'Line 5'
1652+
];
1653+
withTestCodeEditor(TEXT, {}, (editor) => {
1654+
editor.setSelections([
1655+
new Selection(1, 1, 1, 1),
1656+
new Selection(2, 1, 2, 1),
1657+
]);
1658+
1659+
const moveLinesDownAction = new MoveLinesDownAction();
1660+
moveLinesDownAction.run(null!, editor);
1661+
1662+
let model = editor.getModel()!;
1663+
1664+
assert.deepStrictEqual(model.getLinesContent(), [
1665+
'Line 3',
1666+
'Line 1',
1667+
'Line 2',
1668+
'Line 4',
1669+
'Line 5'
1670+
]);
1671+
1672+
assert.deepStrictEqual(
1673+
editor.getSelections()!.toString(), [
1674+
new Selection(2, 1, 2, 1),
1675+
new Selection(3, 1, 3, 1),
1676+
].toString());
1677+
});
1678+
});
1679+
1680+
test('Move lines up', () => {
1681+
const TEXT = [
1682+
'Line 1',
1683+
'Line 2',
1684+
'Line 3',
1685+
'Line 4',
1686+
'Line 5'
1687+
];
1688+
withTestCodeEditor(TEXT, {}, (editor) => {
1689+
editor.setSelections([
1690+
new Selection(3, 1, 3, 1),
1691+
new Selection(4, 1, 4, 1),
1692+
]);
1693+
1694+
const moveLinesUpAction = new MoveLinesUpAction();
1695+
moveLinesUpAction.run(null!, editor);
1696+
1697+
let model = editor.getModel()!;
1698+
1699+
assert.deepStrictEqual(model.getLinesContent(), [
1700+
'Line 1',
1701+
'Line 3',
1702+
'Line 4',
1703+
'Line 2',
1704+
'Line 5'
1705+
]);
1706+
1707+
assert.deepStrictEqual(
1708+
editor.getSelections()!.toString(), [
1709+
new Selection(2, 1, 2, 1),
1710+
new Selection(3, 1, 3, 1),
1711+
].toString());
1712+
});
1713+
});
1714+
1715+
test('Combining up and down', () => {
1716+
const TEXT = [
1717+
'Line 1',
1718+
'Line 2',
1719+
'Line 3',
1720+
'Line 4',
1721+
'Line 5'
1722+
];
1723+
withTestCodeEditor(TEXT, {}, (editor) => {
1724+
editor.setSelections([
1725+
new Selection(1, 1, 1, 1),
1726+
new Selection(2, 1, 2, 1),
1727+
]);
1728+
1729+
const moveLinesUpAction = new MoveLinesUpAction();
1730+
const moveLinesDownAction = new MoveLinesDownAction();
1731+
1732+
let model = editor.getModel()!;
1733+
1734+
moveLinesUpAction.run(null!, editor); // no change since selections are already at top
1735+
1736+
assert.deepStrictEqual(model.getLinesContent(), [
1737+
'Line 1',
1738+
'Line 2',
1739+
'Line 3',
1740+
'Line 4',
1741+
'Line 5'
1742+
]);
1743+
1744+
moveLinesDownAction.run(null!, editor);
1745+
1746+
assert.deepStrictEqual(model.getLinesContent(), [
1747+
'Line 3',
1748+
'Line 1',
1749+
'Line 2',
1750+
'Line 4',
1751+
'Line 5'
1752+
]);
1753+
1754+
moveLinesDownAction.run(null!, editor);
1755+
1756+
assert.deepStrictEqual(model.getLinesContent(), [
1757+
'Line 3',
1758+
'Line 4',
1759+
'Line 1',
1760+
'Line 2',
1761+
'Line 5'
1762+
]);
1763+
1764+
assert.deepStrictEqual(
1765+
editor.getSelections()!.toString(), [
1766+
new Selection(3, 1, 3, 1),
1767+
new Selection(4, 1, 4, 1),
1768+
].toString());
1769+
});
1770+
});
1771+
});
16431772
});

0 commit comments

Comments
 (0)