@@ -12,7 +12,7 @@ import { Selection } from '../../../../common/core/selection.js';
1212import { Handler } from '../../../../common/editorCommon.js' ;
1313import { ITextModel } from '../../../../common/model.js' ;
1414import { 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' ;
1616import { withTestCodeEditor } from '../../../../test/browser/testCodeEditor.js' ;
1717import { 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