First, I want to say thank you so much for this incredible library
My problem is the customization of the folding. Inside codeFolding → config → placeholderText or placeholderDOM I want to display the number of collapsed lines or for example the number of collapsed elements inside an array.
Here’s an img for an example:
Can you pls tell me in which direction I should look in the docs to find how to do this, thank you!
It’s not something that the library supports. If you really need this you’ll have to fork (part of) @codemirror/language/src/fold.ts to implement your own custom folding system.
@marijn would you be open to a PR that implements this functionality? was thinking of updating placeholderText to also accept a function that accepts a single parameter, range ({from, to}), and returns a string.
placeholderDOM/Text are currently called from a place that knows nothing about the folded range, so this is definitely not a matter of simply adding a parameter. It’d need to overhaul the way the widgets used by this code work.
yeah that looks like it would work! just curious why add a new option instead of just passing down the to/from range into the placeholder directly (e.g. in place of the prepare param)
The DOM creation function is called when the widget is rendered. The new function is called when the widget is created, and can be used for multiple renders (for example, when the widget is scrolled out of the viewport and then scrolled back into it). At the time where the widget is rendered, the original folded range may not match the current range for that fold anymore (and widgets don’t know their position, so, as I mentioned before, that information just isn’t available in the code that calls placeholderDOM).