Add a title with “# Title A” then a subtitle with “## Subtitle” and then again any title with “# Title B”
Add some content below of each of the titles
Fold the subtitle
You will then see, that subtitle and the next title will have no gap between them, which makes reading a bit difficult.
If you add a newline before “# Title B” you now have a fitting gap.
So far so good.
But now expand and fold the subtitle again!
You will see that the subtitle “ate” the new empty line!
Will leads in the subtitle growing over time with more and more empty lines and you never will have the distance between the titles.
Proposed Solution
For folding, only fold up to the last line with content, but NOT empty lines!
Trailing empty times should never be folded - they don’t belong to the folded section but to the containing file itself.