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

Improve indentation of lines #28658

Closed
rebornix opened this issue Jun 13, 2017 · 9 comments
Closed

Improve indentation of lines #28658

rebornix opened this issue Jun 13, 2017 · 9 comments
Assignees
Labels
editor-autoindent Editor auto indentation issues feature-request Request for new features or functionality

Comments

@rebornix
Copy link
Member

Auto indent support for type, move lines and copy/paste

Type

defend

Move Lines

movelines

Copy Paste

copypaste

@borekb
Copy link

borekb commented Jun 15, 2017

Is this universal across languages? Does that mean that VSCode will finally be able to re-indent? Related: #19847

Thanks for your work on this.

@rebornix
Copy link
Member Author

@borekb first of all, languages need to define indentation rules, otherwise we don't know how to adjust the indentation. secondly embedded language may not work properly as the language service for embedded languages are not avail if you don't open the file marked as that particular language.

@vvs
Copy link

vvs commented Jun 18, 2017

Please consider adding a keybinding to "auto-indent current line" behavior, similar to what other editors do, like in Atom, with the use of editor:auto-indent:
'.platform-win32 atom-text-editor': 'ctrl-i': 'editor:auto-indent'

, or like in Sublime:
{ "keys": ["f12"], "command": "reindent", "args": {"single_line": true} }

As far as I can tell, currently there is no way to auto-indent the current line.

@rebornix
Copy link
Member Author

@vvs

auto-indent the current line

are you referring to run a command to adjust the indent of current line? If so add an optional argument to reindent all lines can be a solution.

@vvs
Copy link

vvs commented Jun 20, 2017

@rebornix

Yes, please. Essentially, there should be a way to do 3 things via keyboard shortcuts:

  • Indent the whole file (as far as I understand reindentAllLines does that currently)
  • Indent the selection
  • Indent the current line (when there is no selection)

@borekb
Copy link

borekb commented Jul 11, 2017

Just tried the behavior in 1.14 in a JSON file, it seems that the internal engine for indentation is becoming great but I'm still missing the command(s) to re-indent just the current line or the selection as @vss said. Ctrl+I is actually the very command I have it mapped to :)

Actually, thinking about it some more, I very rarely re-indent the whole file and almost always care only about the current line or small chunk of code. So if it was up to me, I'd propose a change of behavior of editor.action.reindentlines (should be editor.action.reindentLines, see the upper-case L) to this:

  • If there's no selection, re-indent the current line.
  • If there's a selection, re-indent all the lines it is touching.

Full file re-indentation would be done by simply Ctrl+A and kbd(editor.action.reindentLines).

Thanks for your continuing work on this!

@rebornix rebornix added the feature-request Request for new features or functionality label Aug 11, 2017
@antcodd
Copy link

antcodd commented Oct 25, 2017

The current behaviour of reindent lines indenting all lines is very confusing. To me the main use for that command would be to reindent blocks after typing in an order not handled by the above improvements. The most common case is wrapping existing code in if { }, such as after pasting. Ideally the language indentation rules would handle this case (I am using C) but the ability to do a manual fixup of crazy indenting without affecting the rest of the file is useful and something I use frequently in vim. In this case I was actually trying to work around #6392.

PR #35594 looks like it changes Reindent Lines to reindent the selection when there is a selection. I think I prefer @borekb's suggestion of reindenting the current line with no selection. The current reindent all feature could be kept as a separate command in which case it should probably be called Reindent Document for consistency with Format Document and to actually be clearly named. I'm not sure if it is also feasible to have Format work over a range?

I also notice that reindent lines also doesn't respect editor.trimAutoWhitespace, re-adding space in blank lines all through the file. Is there an issue for that?

This is even more dangerous now that the default behaviour is to not show whitespace changes in diff or the git changes gutter.

@borekb
Copy link

borekb commented Oct 25, 2017

I also notice that reindent lines also doesn't respect editor.trimAutoWhitespace, re-adding space in blank lines all through the file. Is there an issue for that?

I don't think there is and you're right that it's one of the small but annoying issues with the current implementation. In my own setup, I have .editorconfig that influences how empty lines are treated, ideally it would be taken into consideration but I acknowledge that .editorconfig is supported via extension, not core.

@alexdima alexdima added the editor-autoindent Editor auto indentation issues label Oct 26, 2017
@rebornix
Copy link
Member Author

This issue was created for tracking the todos we were working on auto indentation. Issues mentioned above are being tracked in separate issues so we close this one for better issue tracking.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-autoindent Editor auto indentation issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants