FoldingBuilder behavior for single line
Hi,
I have added FoldingBuilder for my custom language. It works fine with multi-line text (see the below screenshot).

When there is single line it doesn't show any visual indicator that expand/collapse option is available. But it works if I use (cmd + shift + A) -> collapse or cmd -.


Is this the expected behavior?
I need to show the visual indicators for the single line as well. Any suggestions on how to achieve this?
Please sign in to leave a comment.
It's possible to make single-line folding regions have folding anchor displayed in editor by calling
editor.getSettings().setAllowSingleLogicalLineFolding(true)
Thanks for the reply.
I am not sure where to call editor.getSettings().setAllowSingleLogicalLineFolding(true) because while building folding regions, I don't have the reference to the editor instance.
public FoldingDescriptor[] buildFoldRegions(@NotNull ASTNode astNode, @NotNull Document document) {}
Yes, it won't be so straightforward. Probably you can try setting it for all editors corresponding to a given document, obtained via
com.intellij.openapi.editor.EditorFactory#getEditors(com.intellij.openapi.editor.Document)
I tried the above approach but it is still not showing folding anchor.
Can you debug the following method to see why your folding region is not picked:
com.intellij.openapi.editor.impl.EditorGutterComponentImpl#doPaintFoldingTree
It's possible that explicit editor repaint will be required after setting change.
The folding anchor is not visible because the last call is returning false(isSoftWrappingEnabled).
How to enable soft wrap?
Thanks. Sorry, I didn't look at this in details myself first. It turns out it's not possible currently to display folding anchors for a folding region located completely inside one visual line. The setting mentioned previously enables showing them only for single-logical-line regions spanning several visual lines due to soft-wrapping.
If that matters, folding actions (expand/collapse region) should still work fine for single-line regions.