Vscode: Drunk behavior of moveLinesDownAction

Created on 23 Jul 2018  路  3Comments  路  Source: microsoft/vscode

  • VSCode Version: 1.25.1 (1.25.1)
  • OS Version: OSX 10.11.6

Steps to Reproduce:

  1. Select brackets block
  2. alt+down

vscodebug

bug editor-autoindent insiders-released

Most helpful comment

VSCode simply shouldn't touch the indenting when moving lines up and down. It's not moving a statement, it's moving the whole line. So the editor should just stop trying to be smarter than it can be.

The correct indentation is very hard to predict with 100% accuracy, and even 99% isn't good enough, because the remaining 1% will drive one insane. Unfinished code is likely not (yet) well-formed, making it impossible to correctly predict the indentation the developer intents to go for.

All 3 comments

Good catch and it helps me understand what's going on there.

Let me use a simple if block to describe the root cause here, will work on it after the issue grooming.

console.log();

if (true) {
  console.log();
}

We have 5 lines of code here. Say if we are going to move the 3rd line down, internally we cut the 4th line and paste after 2nd line. So console.log(); will be the new 3rd line, and if (true) { will be the new 4th. To adjust the indentation of if (true) { we need to check the onEnter rules on the new 3rd line console.log(); however right now, we are still checking if (true) {, which will tell us to increase the indentation.

The expected result should be

console.log();

console.log();
if (true) {
}

However due to the wrong onEnter rules checking, we get

console.log();

console.log();
  if (true) {
}

VSCode simply shouldn't touch the indenting when moving lines up and down. It's not moving a statement, it's moving the whole line. So the editor should just stop trying to be smarter than it can be.

The correct indentation is very hard to predict with 100% accuracy, and even 99% isn't good enough, because the remaining 1% will drive one insane. Unfinished code is likely not (yet) well-formed, making it impossible to correctly predict the indentation the developer intents to go for.

Fully agree with @thany's statement. There are a lot of auto indentation issues when moving code up and down (see other referenced issues). It might be best to (allow us to) disable auto indentation when moving code up and down, because it's clearly not working as expected in a lot of cases, and it doesn't seem like these issues are high on the priority list.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VitorLuizC picture VitorLuizC  路  3Comments

philipgiuliani picture philipgiuliani  路  3Comments

borekb picture borekb  路  3Comments

villiv picture villiv  路  3Comments

mrkiley picture mrkiley  路  3Comments