Try to enable the option "Save spaces in the run" in "Settings / Editor / General".
You can choose whether this should be done for all lines or only lines that you are changing to avoid creating unnecessary differences.
Spaces are separated when you explicitly press CTRL + S or automatically after some period (IntelliJ has autosave).
It should be noted that if you hover over an empty line and there are spaces in front of it, pressing CTRL + S will not erase spaces, because it will probably be annoying when your cursor starts to jump to the beginning of the line if the file was autosaved IntelliJ (I read somewhere on YouTrack that it was a design decision).
Here is a screenshot of the option I am describing:

source share