Strange indentation behaviour for empty lines
Hi,
I have set up Webstorm to indent empty lines so my caret does not jump around when moving in the code. Unfortunately the indentation when formatting in my code is always off one level, indentation after hitting enter works correctly. While I wanted to create a minimalistic example I noticed the indentation is changing for code with doc comments.
What I found is that this code works (pipes show the indentation for the empty line):
Ext.define('foo', {
doBar: function() {
var bar = this;
|
bar.doBar();
}
});
But when I add a doc comment indentation is broken:
Ext.define('foo', {
/**
* foo bar
*/
doBar: function() {
var bar = this;
|
bar.doBar();
}
});
Is there any workaround to fix the indentation?
Please sign in to leave a comment.
Enter works equally well for me when using your examples - new line is correctly indented on Enter.
What IDE version do you use? Did you try re-formatting the code prior to hitting Enter? Enter indents a new line according to code style preferences, if your current code formatting doesn't match the preferences, new lines will be misaligned
>I have set up Webstorm to indent empty lines
Please can you clarify what you did namely?
To clearify: Indentation is only broken after reformatting.
Enter after reformatting is working correctly. The caret position does not matter, even hitting Enter on the wrongly indented line indents the appearing line correctly.
> Please can you clarify what you did namely?
I checked the setting Keep indents on empty lines in Editor > Code Style > JavaScript > Tabs and Indents. I tried messing around with everything I could find that has to do with indent and removing of blank spaces but nothing worked so far.
> What IDE version do you use?
>To clearify: Indentation is only broken after reformatting.
still not sure I follow you.. Do you mean that existing indents on _empty_ lines change to incorrect ones after Code | Reformat Code? This doesn't happen to me... Indents are kept as is if Keep indents on empty lines is enabled
> Do you mean that existing indents on _empty_ lines change to incorrect ones after Code | Reformat Code?
Yes that is exactly what is happening to me.
.jsfile that shows up the issue plus your code style settings (<IDE config dir>\codestyles\<scheme name>.xmlif you are using IDE-level scheme, or.idea\codeStyles\Project.xmlwhen using a project scheme) would be helpful.The minimal example that shows my issue is in the first post.
Project.xml
Code style settings:
You have included both the project and IDE code style schemes. Which one do you actually use? See what scheme is selected in Settings | Editor | Code Style, Scheme:
I use the helix scheme:
Still no luck in recreating the issue... Indents on empty lines look OK after re-formatting the code when using your scheme:
Do you have any file watchers enabled? Can you recreate the issue in a new project?
I have no file watchers enabled and the issue cannot be recreated in a new project.
I might have found why this is happening. I have set up the reformatter to only affect the changed text like this:
When I change it to Whole file the indentation is correct. But sadly I do not want to reformat the whole file...
I've the same problem in IntelliJ with Java code. I'm using IntelliJ IDEA 2019.2 (Ultimate Edition) (Build #IU-192.5728.98, built on July 23, 2019) with the Save Actions plugin. These are the steps to reproduce the error:
In the line before the field assignment, now are just two spaces instead of four.
If I reformat the whole file manually now (Code / Reformat Code) the indents are correct again.
And as you can see it doesn't need a comment for the error to show up.
These are my code style settings.
I created a Issue in YouTrack