How do I stop Android Studio from reindenting my e...
# compose
r
How do I stop Android Studio from reindenting my entire file just because I autocompleted something in a Composable function? Screenshots in thread...
✔️ 1
❤️ 2
1
Becomes this. It even changes other functions. Where is the "leave my damn code alone" switch. 🙂
d
It's actually so annoying. Especially when you don't see it happen until you make an PR or something, ugh.
d
One approach I find success with is writing the code in the way it is reformatted to in the first place.
There are many advantages to the way it reformats the code
d
Works if you own the code.
d
Yes it does!
r
Haha. No, I will not submit to the arrogant dictatorship of the IDE. 🙂 Why have any of the other 100's of indentation format preferences, then. Just reformat everyone's code the way some developer thought they should write it.
d
Alternatively there are settings in the IDE to not do this.
r
I'm looking. Haven't found it yet.
d
The decisions to reformat the code in the way it does was not made by a single person. It was made by many over many discussions and for reasons that go beyond the context of the IDE.
Check in commit settings?
Ctrl k
Maybe something in the pre commit settings? Or on save?
Or changing the character limit?
The character limit on lines might be like 80 or 100.
r
It's nowhere near my line limit and I'm not committing anything. Having an indentation standard is fine. Imposing it while I'm typing, on code that is offscreen, is out of character with the way the rest of the code formatting suggestions behave.
d
Or you could check which style guide is enabled.
Hmm 🤔
r
Found it!
Preferences > Editor > Code Style > Kotlin > Compose > Compose formatting for modifiers.
👌 1
d
There ya go!
Nice!
r
Ideally there would be a way to apply it to a selection, when desired, but this will do for now.
d
There is
Select the code you want formatted and then use the format action shortcut.
You can also format whole files or even entire directories.
The same goes for import optimization
r
@dewildte What do you mean "format action". The command I see is in the menu under Code > Reformat Code (⌥⌘L on my Mac). But it doesn't make the changes if I've unchecked that box in preferences.
d
Yes that's the one! By yeah it will do nothing if you have turned off the formatter related to that chunk.
I guess you can't have your cake and eat it too. 😞
r
This seems like a bug to me. Having a formatting rule enabled by default is fine, but shouldn't it behave like the other formatting rules - apply only to the selection, or the statement you are editing?