microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.71k stars 29.08k forks source link

Ctrl+Alt+Down (selecting lines) and Alt+Up (moving them) moves only 1 line #47151

Open user3323 opened 6 years ago

user3323 commented 6 years ago

ctrl alt down

user3323 commented 6 years ago

@alexandrudima

feature request? =\

alexdima commented 6 years ago

Yes, the move or duplicate lines actions are only partially multi-cursor aware and they create bogus intersecting/conflicting edits in these cases.

Related: #41277, #40646, #19621

PR welcome in https://github.com/Microsoft/vscode/blob/1e5c0c3e4e11af82e82d7761d7875646d1c6336b/src/vs/editor/contrib/linesOperations/linesOperations.ts#L102-L104 . The current support for multi-cursor is to loop over all the selections and generate a move lines command. But a correct implementation would only invoke the command once in the case that multiple cursors sit on the same line, or that multiple cursors are within 1 line distance of each other, etc.

irrationalRock commented 6 years ago

Hi, I am interested in this bug.

I have made some changes that partially fix this bug: partial_works

I have a question about the comment you made about this line:

for (var i = 0; i < selections.length; i++) { 
 commands.push(new MoveLinesCommand(selections[i], this.down, autoIndent)); 
} 

Can you elaborate more about this? I'm wondering how you would invoke the command once instead of multiple times.

alexdima commented 6 years ago

Instead of using commands (which are single-cursor aware), It is possible to use editor.executeEdits which allows to apply N edits at the same time and set the N resulting selections.