Reformat is compressing lines of code into a single line
It will take:
and make it like
Obviously, I prefer the first. This seems to happen for all `if` statements that are not bracketed, it will simply grab an `else` on the next line and move it up to the same one.
The behavior only started recently, and I can't think what change could have prompted it.
Edit: I've tried
and that has not helped. No extra plugins enabled.
请先登录再写评论。
You can try enabling the Keep when reformatting > Line breaks in Settings | Editor | Code Style | JavaScript | Wrapping and Braces - does it work for you?
Unfortunately no. I did try that.
edit: and to be clear, it's not a matter of keep or not. The “reformatting” I desire is to not have two lines of code on the same line. It's very weird it would start doing this.
Unfortunately I failed to reproduce the issue
Could you share a complete code snippet that reproduces it plus your code style preferences (
<IDE config dir>/codestyles/<scheme name>.xml
) if you are using IDE-level scheme, or.idea\codeStyles\Project.xml
when using a project scheme)?This is a really basic project I just set up to test, and it has the same issue as my other projects.
edit: tested again and it will do the same thing with the default xml.
Video of doing repro here
2023-11-10 12-06-36.mp4
Sorry, my comment seems to be stuck “pending approval.”
But in a nutshell, it does it with the default profile and this snip:
With your code style settings, the code is formatted as follows for me:
As you can see, the line breaks are not removed
Please share a sample project that reproduces the issue (along with the
.idea
folder)I got hit with “pending approval” again in my comment for sharing a link to the files on onedrive, and I can't see a way to attach a zip directly. My previous comment still has not cleared.
On one drive it's Ai1LfYkLJyBJi6M0RK6Q3S2y6ISTPg?e=w838x2
In your project, you are using the IDE-wide ('default') code style scheme I have no access to
When using my code style settings, formatting works as expected, line breaks are kept
Note that the second re-formatting removes the line breaks despite the option
To be clear, I don't mind
What I never want is
When you say “the second re-formatting removes the line breaks” are you saying that it produces the first example or the second?
I don't ever want the second, and I want the IDE to fix the damage it did when it produced the second.
edit: the “project wide default” is simply this xml:
<code_scheme name="Default" version="173" />
I have set everything back to defaults that I can find!
edit: video link s!Ai1LfYkLJyBJi6MaWQgEbfKF-QCfzw?e=v4lXYp
The second - it removes the manually added line breaks, overriding the Keep line breaks option
But this only happens if you hit
Ctrl+Alt+L
2 times in a row, without making changes to your code in betweenpress ctrl + alt +L 2 times
then in the emergent windows click NO and select (dont ask again).
thats it..
> press ctrl + alt +L 2 times
then in the emergent windows click NO and select (dont ask again).
I press ctrl + alt +L 2 times, but no emergent windows shown.
the IDEA remove break lines without my approve.
IntelliJ IDEA 2024.3.3 (Ultimate Edition)
Tim Andy the formatter behavior depends much on the language.
Could you please clarify what file type you are working with and if possible, share a sample code snippet to reproduce? Thanks!
Tim Andy please check if you have the Reformat again to remove custom line breaks option enabled in Settings | Editor | General | Smart Keys; when this option is enabled, invoking the Reformat Code or Reformat File actions the second time after the code has been reformatted will remove custom line breaks. When it's disabled, invoking the actions the second time opens a dialog.
Elena Pogorelova Thanks for your answer, It works.