CodeblockCustomizer icon indicating copy to clipboard operation
CodeblockCustomizer copied to clipboard

Initial folded state for blocks with too many lines

Open dimateos opened this issue 4 months ago • 6 comments

Semi-fold is VERY nice, but IMO would be even better if the blocks above certain lines could be initially folded.

Could use the same amunt of lines for the Semi-fold setting, but ideally a separate one would be preferred e.g.

  • I want auto fold for >20 lines
  • But then only render 10 (+the faded ones)
  • Might address what https://github.com/mugiwara85/CodeblockCustomizer/issues/116 was about?

BTW it is a bit misleading that the setting explicitly states "number of visible lines" and then you can see like 4 more and even interact with the first ones very well. So maybe consider:

  • Mention the additional faded lines
  • Make the setting match exaclty

This feature might be more involved than e.g. https://github.com/mugiwara85/CodeblockCustomizer/issues/132? But anyway, this seems less important as a Qol’ as usually codeblocks aren’t huge.

Best regards again!

dimateos avatar Sep 15 '25 16:09 dimateos

Auto semi-fold is also a good idea. But not quite sure what you mean by that, that "auto fold for > 20 lines, but then only render 10+ lines"? It's hard to find out what people want, when they open an issue, and then stop replying, that's why #116 was closed. Number of visible lines means the lines which remain fully visible and won't have the fadeout effect. It is also explained in the README https://github.com/mugiwara85/CodeblockCustomizer?tab=readme-ov-file#semi-fold What do you mean by "Make the settings match exactly?" I will try to implement this as well before the next release.

mugiwara85 avatar Sep 15 '25 16:09 mugiwara85

Auto semi-fold is also a good idea.

Thanks and I appreciate a lot you quick answers!

Auto semi-fold is also a good idea. But not quite sure what you mean by that, that "auto fold for > 20 lines, but then only render 10+ lines"?

Sure, let me explain. For example, you set semi fold behavior for codeblocks above 10 lines (+4 fade). Then if you simply decide to reuse this settings' value for triggering the suggested feature: "initial fold state for long codeblocks" Then small codeblocks of >=14 lines will start already folded at the semi fold state... which then expanded results in basically the same:

Image

One way to help with this would be if the "initial fold state for long codeblocks" is a separate setting from semi fold. Then you could set it to like 20, and those would collapse to a semi-fold state of 10+4 (or the default 5+4 setting)

But this may hint at another issue tho, the posted image might be something to be avoided even ignoring the proposed new feature of "initial fold state for long codeblocks". How about replacing the current setting with:

  • Setting to enable semi-folded codeblock: minimun amount of lines
    • This setting could be used for the "initial fold state for long codeblocks" as in this case it seems compatible
  • Setting to set the amount of lines for semi-fold

This two settings combined could avoid the posted image!

What do you mean by "Make the settings match exactly?"

Sorry my fault. I only looked at the obsidian plugin config, not the readme: https://github.com/mugiwara85/CodeblockCustomizer/blob/3aca1fe2d0243412c3e72cc1f1ff9b2b398c29b8/src/SettingsTab.ts#L1167

It actually mentions looking up the readme for more info tho. I was merely suggesting that this setting description could be edited to also mention the +4 faded lines OR that the amount of lines displayed could be N-4 +4 faded to exactly match the setting value.

So as you can see, nothing important, do as you wish!

dimateos avatar Sep 15 '25 20:09 dimateos

I have to admin, I had read this post at elast 10 times, to fully understand wht you described :D So before I implement it, please verify: Correct me if I am wrong, but as I understood, you want to auto-semi-fold long code blocks when the document opens, right? I decided that I add two more options:

Image

My reason behind this, is that if someone just wants to use semi-fold then he can enable it and that's it. if someone also wants to use auto semi-fold, he can enable it as well. What you recommended (the two setting to replace the existnig logic) is also a good idea, but I think that offers less felxibility, to what I proposed.

What do you think?

mugiwara85 avatar Sep 22 '25 00:09 mugiwara85

I have to admin, I had read this post at elast 10 times, to fully understand wht you described :D

Oof so sorry, my bad, thanks for taking the time.

Yeah what you suggest is the original idea and there is no need to complicate it further. It is more flexible and seems simpler for the user and to implement!

Best regards!

dimateos avatar Sep 22 '25 12:09 dimateos

@dimateos I added the new option. Feel free test it. I am not yet sure if the option name is correct. What do you think about it? If you want you can also retest the snapshot button. It should correctly work now even if scaling is increased. One specific problem you mentioned, where the button was displayed on folded state, but could not be clicked, I could not reproduce. I think that might have happened because you switched themes, and the codeblock "stuck" in a semi-folded state (in this case the button should be visible), but the new theme you switched to, there was semi-fold not enabled, and therefore it was fully folded. But it is just a guess. If you want you can also check out #131 :)

mugiwara85 avatar Sep 23 '25 00:09 mugiwara85

Oh I forgot. The initial semi-folded state is only applied to code blocks which have a header. Theoretically I could also apply this to all code blocks (without a header), but only then if the uncollapse button is enabled. Otherwise you wouldn't be able to uncollapse it. What do you think?

mugiwara85 avatar Sep 23 '25 00:09 mugiwara85