mugiwara85/CodeblockCustomizer

Feature request: toggle folding of all code blocks on page

Closed this issue ยท 9 comments

Firstly this is a great plugin, thank you for creating it.

When a note contains many large code blocks, it can be time consuming to scroll through the page. A solution to this would be to have some way of globally setting the fold status of all code blocks on a page. That is, when toggled, all folded code blocks becomes unfolded. When toggled again, all unfolded code blocks become folded.

Would this be a command as opposed to a setting? Would you want any specific codeblocks to ignore this command if they have a certain parameter set? (I.e. global_fold:false)

A setting that makes code blocks globally folded or unfolded by default would certainly be useful. I had originally had in mind that it would be a command to quickly fold all code blocks in a given page to make navigating the page faster. For me personally I don't see myself using a global_fold parameter all that often.

I understand your concern but creating a setting in the settings tab would be cumbersome. Every time you want to collapse/uncollapse all code blocks you'd have to go to the plugin settings. This in my opinion makes this solution definitely not ideal. Implementing a new parameter goes against the logic because it would have an effect for all code blocks on the page. And what if you forget it in which code block you defined it? So, this is also a no.
One way I could imagine this would be the following. You'd have a toggle in the settings tab. If you enable it, then a button would be displayed in the header. Clicking this button would collapse/uncollapse all code blocks on the page. This however requires that you have made some settings so the header is displayed before. Still not happy with this solution though.
But the easiest way is the already existing one: why not type fold in the first line? Then the code blocks are collapsed by default.

Rather than involving the settings tab at all, could we just add two obsidian commands (called from command palette) to 'fold all codeblocks' and 'unfold all codeblocks'. This way it doesn't clutter the plug-in and the option is there for users who would benefit.

I agree that the suggestion for a parameter which ignores this command is a bit silly. I think it's too niche to worry about excluding certain codeblocks from such commands if they're added.

A command called from the command palette sounds like it would work for what I'm imagining

I added 3 commands:

  • Fold all codeblocks
  • Unfold all codeblocks
  • Restore default fold state

Ist this ok for you? I have just a minor problem with it I have to fix, but generally it works. It will then available in the next release.

That sounds great, thank you!

Available in version 1.2.0. Please also read the README.