When folding, don't include trailing empty lines

Reproduction:

  1. Add a title with “# Title A” then a subtitle with “## Subtitle” and then again any title with “# Title B”
  2. Add some content below of each of the titles
  3. 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.

6 Likes

Did not yet get much attention :slight_smile:

But I think it is obvious … probably, I could not make my point clear enough.

Any section should END with the last line of content!

This seems logical, but it is not currently true in the implementation.

It should be fixed easily.

I retitled the thread to emphasize the request rather than the problem. (Was “Folding does fold too much - including trailing empty lines”.)

1 Like

That does not remove the problem, or?

The previous title stated the problem that the requested feature would solve. The new title describes the feature itself.

If you mean this doesn’t solve the problem, that’s true.

1 Like

Here is a screenshot highlighting the issue:

Without folding the content looks as follows:

An empty line after the folded heading would make the fold look better. Currently it hangs ontop the following heading.

1 Like

Yes.

Any chance for this?
:wink:

I agree. It would make folded headers much easier to read.

Friends and fellow folders — I bring magic from CSS wizard @sailKite in the form of a snippet they have graciously provided at my humble request!

/* Put some vertical space under folded headings for better readbility. 

Courtesy of @sailkite https://discord.com/channels/686053708261228577/702656734631821413/1136455149691347045

Re: feature request https://forum.obsidian.md/t/when-folding-dont-include-trailing-empty-lines/43973

"and of course you can do it a different way where instead you modify the top padding on things that come after
"which may have relevance in some cases but i'm struggling to think of any off the top of my head... maybe in embeds or something"
For a rough version of this different way see https://forum.obsidian.md/t/when-folding-dont-include-trailing-empty-lines/43973/10
*/


.is-collapsed > :is(h1, h2, h3, h4, h5, h6),
.HyperMD-header:has(> .cm-fold-indicator.is-collapsed, > .cm-foldPlaceholder) {
    padding-bottom: 24px;
}

It doesn’t preserve your literal blank lines but it adds some padding under folded headings for much the same effect.

Re: the alternate approach mentioned in the snippet’s comment:

“the snippet for that approach would look more like this, roughly”

.is-collapsed:has(> :is(h1, h2, h3, h4, h5, h6)) + div,
.HyperMD-header:has(> .cm-fold-indicator.is-collapsed, > .cm-foldPlaceholder) + .cm-line {
    padding-top: 24px;
}