phpstormphpstorm-2017.2phpstorm-2018.1

Indents after pushing Enter button in PhpStorm


I've been using PhpStorm for a long time and I haven't had this problem before. The problem is that when I type some pare tag, for example, <div></div> (there is indent from the beginning of the line) and the cursor is in the middle of this tag and after I push Enter button the closing tag just goes to the beginning of the line.

The interesting fact that in .php file everything is OK. The problem only with .html extension. I just don't know what I could do to make IDE acts like this.

I have already checked all the adjusting in the Preferences -> Code style -> HTML. Everything is the same as in PHP (and I've pushed the button "Restore Defaults").

It works like that (after pushing Enter button):

      <div>

</div>

And I want it be like that:

     <div>

     </div>

Solution

  • From your other post:

    I put first some indent to the tag and than push "Enter button". So the first part of the tag stays where it was, but the other goes to the beginning of the line

    So, you have your code formatted manually so that the indentation differs from the one you'd get when performing Code > Reformat Code. 'Smart indent' (indenting code on Enter - Settings | Editor | General | Smart Keys, Enter section) doesn't care about your manual indentation, created indents are based on code style settings rather than your manually created indents. You can turn it off - the next line will always be indented to the same level as previous in this case.

    If reformatting the code with Code > Reformat Code doesn't help, it must be the issue with either the code formatting preferences or file associations... Do you have any custom plugins installed? Svelte plugin, for example, registers .html files as Svelte Html Components (https://github.com/dschulten/sveltejs-idea-plugin/issues/2, https://github.com/dschulten/sveltejs-idea-plugin/issues/6), causing similar issues.

    Please also check if Keep white spaces option is enabled in Settings | Editor | Code Style | HTML | Other - when it's ON, existing indents don't change on reformatting