@@ -184,41 +184,50 @@ abstract class AbstractMoveLinesAction extends EditorAction {
184184 movingMultipleLines = selections [ 0 ] . endLineNumber !== selections [ selections . length - 1 ] . endLineNumber ;
185185
186186 if ( movingMultipleLines ) {
187+ // Stash selections while processing, set new selections +/- line-change only
188+ for ( const selection of selections ) {
189+ let startCol = selection . getStartPosition ( ) . column ;
190+ let startLine = selection . getStartPosition ( ) . lineNumber ;
191+ let newStartLine = this . down ? startLine + 1 : startLine - 1 ;
192+
193+ let endCol = selection . getEndPosition ( ) . column ;
194+ let endLine = selection . getEndPosition ( ) . lineNumber ;
195+ let newEndLine = this . down ? endLine + 1 : endLine - 1 ;
196+
197+ newSelections . push ( new Selection ( newStartLine , startCol , newEndLine , endCol ) ) ;
198+ }
199+
187200 // Work only with one selection per line
188201 selections = selections . filter ( ( s , idx , arr ) => {
189202 return arr . map ( sel => sel [ 'endLineNumber' ] ) . indexOf ( s [ 'endLineNumber' ] ) === idx ;
190203 } ) ;
191204
192205 selectionDirectionDown = selections [ 0 ] . endLineNumber < selections [ selections . length - 1 ] . endLineNumber ;
193- }
194- }
195206
196- if ( movingMultipleLines ) {
197- editor . pushUndoStop ( ) ;
207+ editor . pushUndoStop ( ) ;
198208
199- if ( selectionDirectionDown === this . down ) {
200- selections . reverse ( ) ;
209+ if ( selectionDirectionDown === this . down ) {
210+ selections . reverse ( ) ;
211+ }
201212 }
202213 }
203214
204215 for ( const selection of selections ) {
205216 if ( movingMultipleLines ) {
206- editor . executeCommand ( this . id , new MoveLinesCommand ( selection , this . down , autoIndent , languageConfigurationService ) ) ;
207-
208- let editorSelection = editor . getSelection ( ) ;
209- if ( editorSelection !== null ) {
210- newSelections . push ( editorSelection ) ;
217+ // If we are at the beginning/end of document and multiple lines are moved, abort.
218+ if ( ( selection . startLineNumber === 1 && ! this . down ) || ( selection . endLineNumber === editor . getModel ( ) ?. getLineCount ( ) && this . down ) ) {
219+ editor . pushUndoStop ( ) ;
220+ return ;
211221 }
222+
223+ editor . executeCommand ( this . id , new MoveLinesCommand ( selection , this . down , autoIndent , languageConfigurationService ) ) ;
212224 } else {
213225 commands . push ( new MoveLinesCommand ( selection , this . down , autoIndent , languageConfigurationService ) ) ;
214226 }
215227 }
216228
217229 if ( movingMultipleLines ) {
218230 if ( newSelections . length > 1 ) {
219- if ( selectionDirectionDown === this . down ) {
220- newSelections . reverse ( ) ;
221- }
222231 editor . setSelections ( newSelections ) ;
223232 }
224233
0 commit comments