Closed net closed 7 years ago
For this particular feature request, I think it can be done in an extension. Feel free to contribute!
@rebornix I've looked into making this as an extension, and it seems to me that VSCode does not expose the necessary APIs for this to work. We need a method to get the proper indentation level of a given line.
Should I create a new issue?
@net good to know you are looking into this issue. Actually it's easy to get an indentation level of a line, you can get the tab size by activeTextEditor.options.tabSize
and calculate the view column width of the leading white spaces.
For example, you have a line \t
and the tab size is 4, you can do the calculation and figure out that the indentation level is 1. We have similar code in our core but as it's not complex and not generally important so we may not want to expose it through extension host. Make sense?
@rebornix I think you're describing a method to get the current indentation of a line. What I need is a method to get the ideal indentation of a line as defined by the language syntax configuration, using OnEnter
rules, bracket character pairs, etc.
@net I see. In this case, I think this issue actually can be marked as feature request :)
I really want to switch to VSCode but it's missing an essential editor action. Many editors have an "auto-indent" action which automatically indents the current line—or a selection of lines if multiple lines are selected—to the appropriate indentation when used.
This is not the same as a normal indent: Auto-indent should indent the line immediately to the correct indentation (to the best of the editor's ability, of course) upon use, rather than requiring multiple uses to reach the expected level. If the current line is indented too far, auto-indent should deindent the line appropriately.
This is not the same as Format Selection: Auto-indent only indents/deindents, it does not preform any other formats. Additionally, auto-indent can be activated without a selection; the target line is inferred from the cursor's position. Auto-indent should work without a formatter, as indentation can be computed the same way as a new line's indentation.
I find it much more efficient to bind
tab
to theauto-indent
action, and use⌘[
/⌘]
to manually adjust indentation.Auto-indent in Sublime Text: https://coderwall.com/p/7yxpdw/auto-indenting-on-sublime-text-3
Auto-indent in Atom: http://stackoverflow.com/questions/22611377/auto-indent-code-in-atom-editor
This behavior is default in Spacemacs (and maybe Emacs?).