Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript: Improve indentation on insert with trailing newline #85781

Open
SillyFreak opened this issue Nov 28, 2019 · 2 comments · May be fixed by #182934
Open

JavaScript: Improve indentation on insert with trailing newline #85781

SillyFreak opened this issue Nov 28, 2019 · 2 comments · May be fixed by #182934
Assignees
Labels
editor-autoindent Editor auto indentation issues help wanted Issues identified as good community contribution opportunities javascript JavaScript support issues on-unit-test typescript Typescript support issues under-discussion Issue is under discussion for relevance, priority, approach
Milestone

Comments

@SillyFreak
Copy link

Let's say I have the following JS snippet:

() => {
  a
}

() => {
  b
}

Now select the entire 'a' part, from the start of line 1 to the start of line 4, i.e. including a trailing newline, and insert it at the start of the line now containing 'b'. The result is this:

() => {
  a
}

() => {
  () => {
    a
  }
    b
}

The 'b' is now over-indented because that line received additional indentation at insert. Expected behavior: the 'b' should remain at its original indentation level. I can confirm this behavior at least for JS and JSON files.


The reason I care is that selecting whole lines with the keyboard is the easiest from start to start, so this kind of pasting is very common in my workflow. I often do Ctrl+C, Ctrl+V, Ctrl+V to duplicate lines; with this bug, this will add two additional indentations to the next line, which is potentially unrelated to the copied lines.

@mjbvz mjbvz added editor-autoindent Editor auto indentation issues help wanted Issues identified as good community contribution opportunities javascript JavaScript support issues labels Dec 2, 2019
@alexdima alexdima removed their assignment Dec 3, 2019
@jzyrobert
Copy link
Contributor

jzyrobert commented Dec 4, 2019

Would something like this be acceptable?

On the last paste line, if

  • range.endColumn is 1 (Just a newline pasted)
  • lineLength of that line is > 0 (So content existed before paste)

Then don't add extra indent?

@SillyFreak
Copy link
Author

I think that's consistent with my mental model, that pasting should behave like the following:

  1. do the paste without any auto-indentation
  2. select exactly the text that was pasted
  3. use tab to indent to the level of the insertion position

So in the case that the insertion range ended at the start of the line (your first condition), the selection from 2. would have an empty last line which would not be indented during 3. I don't care about the second condition too much, as it's trailing whitespace that can be auto-removed. So yes, that sounds good!

@rebornix rebornix added the under-discussion Issue is under discussion for relevance, priority, approach label Nov 3, 2020
@mjbvz mjbvz added this to the Backlog milestone Dec 7, 2022
russelldavis added a commit to russelldavis/vscode that referenced this issue May 19, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue May 19, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines in the same scenarios didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue May 22, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Jun 9, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Jul 18, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Sep 30, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Oct 2, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Oct 3, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Oct 7, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
russelldavis added a commit to russelldavis/vscode that referenced this issue Oct 12, 2023
Fixes microsoft#85781
Fixes microsoft#147223
Fixes microsoft#33760
Fixes microsoft#65614
Fixes microsoft#86301

(Some of the issues above were closed as being limitations of the
regex based indentation rules, but this change is able to fix them.)

Note that ReindentSelectedLinesAction already does the same thing as
this fix (which is what inspired it -- I noticed that running Reindent
Selected Lines on the equivalent code didn't have the same issues): see
https://github.com/microsoft/vscode/blob/6cbd9e8f3c5a59c5b1170aac8f2b5e9b0b4edfee/src/vs/editor/contrib/indentation/browser/indentation.ts#L390-L392
@aiday-mar aiday-mar assigned aiday-mar and unassigned rebornix and mjbvz Mar 8, 2024
@aiday-mar aiday-mar added the typescript Typescript support issues label Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor-autoindent Editor auto indentation issues help wanted Issues identified as good community contribution opportunities javascript JavaScript support issues on-unit-test typescript Typescript support issues under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants