nbadal / ktlint-intellij-plugin

Ktlint plugin for IntelliJ IDEA + Android Studio
MIT License
158 stars 24 forks source link

Add option to run ktlint only when running Reformat Code (Ctrl+Alt+L) #519

Closed vitiasr closed 4 months ago

vitiasr commented 4 months ago

Assume the following case:

image

After selecting the variable name, as shown above, when I click the left curly bracket key on my keyboard, the variable name is not wrapped in curly brackets as expected, because ktlint is being fired automatically and removes them instantly.

It would be nice to have an option to run ktlint only when using Reformat Code (Ctrl+Alt+L).

paul-dingemans commented 4 months ago

If you disable option 'format on save' this should work as you expect.

vitiasr commented 4 months ago

Unfortunately it does not. The only solution I found is to disable the Distract Free mode altogether.

paul-dingemans commented 4 months ago

Just checked it, and the format on save is not related to this.

I can reproduce the behavior you described. Unfortunately, I can not find a solution for this as you want to run Ktlint formatting together with (e.g. after) formatting of Intellij IDEA. For some reason the PostFormatterProcessor hook gets fired once you insert the left curly brace manually.

Interestingly enough, if you use option insert curly braces around variable thePostFormatterProcessor does not get triggered, and you get the behavior you want.

As, this is not something that I can fix in the plugin, I will close the issue.