10
votes

It appears PHPStorm doesn't want to follow the code style I specified. Each time I format an HTML file, it collapses the indentation from this:

<html>
    <head>
        bleh
    </head>
    <body>
        bleh
    </body>
</html>

to

<html>
<head>
<bleh>
    bleh
<bleh>
</head>
<body>
<bleh>
    bleh
<bleh>
</body>
</html>

"bleh" (being all the contained tags) are indented how they're suppose to.
I found the setting: File -> Settings -> Code Style -> HTML -> Other -> "Do not indent children of".
That was filled with several tags which I have already removed (so the text field is empty).
The settings are theoretically applied to the Project scheme which is the current scheme.
However, I haven't fully grasped the concept of what these schemes are, so I may be missing something important.

Pictures:
http://snapshot.overloadproducts.com/7411c9d50e0b43edc76c1e625a38d61c http://snapshot.overloadproducts.com/5a74f83356572f3644a6d52bf2fa1f66

Edit: Opened PHPStorm the next day, and it said the project file had been edited externally, and it needed to refresh. Once it did, it was formatting correctly again.
So somehow the settings file was out of sync and the settings window wasn't saving to the file.
Still a bug in my opinion.

3
The "Do Not Indent Children Of" thing isn't a text box, it's one of the usual pop-up key-value editors dealies. You have to click icon at the end of the text field to bring up the REAL editor. Make your changes there and press "OK". You'll be golden.lucifurious

3 Answers

19
votes

Just go to Setting/preferences -> Editor -> Code Style -> HTML -> Other

Insert new line before: add body.

Do not indent children of: clear all in this form.

3
votes

ANSWER (ON EDIT): For an actual work around, try right clicking your document and clicking "Paste Simple". This will preseve the formatting of the text pasted on the clip-board. Not really a solution as such, but an appropriate workaround.

ORIGINAL:

Did you end up getting an answer for this?

I have the same problem, and for the life of me can't fix it. This is really really annoying, especially seeing as the "preview" pane of what the code formatting should look like isn't accurate - it shows:

<div>
    <div>
        <p>
            Some comment from JetBrains.
        </p>
    </div>
</div>

... but when pasting in text from an editor, it gets reformatted to:

<div>
<div>
<p>
Some comment from JetBrains.
</p>
</div>
</div>

Sorry for posting a comment in the answer section but I don't have 15 reputation.

2
votes

Right below the option "Do not indent children of:" you'll find the option "or if tag size more than" with a default value of 200.

That means that for larger HTML-Files indentation will effectively be disabled. I have no idea why anyone would want that but the way to get rid of this (miss-)behaviour is to remove that value (just leave the field empty).