How to color code folds created via code?

Answered

Hi,

i have a custom editor and i want to added some code folds via

 editor.getFoldingModel().createFoldRegion()

the question now is, how can i color these folds when they are collapsed? Right now they are colored like normal text.

0
4 comments

hi. The fold region colors are configured globally in settings|editor|Color scheme. THere's no way currently to color them individually. 

0

Hi,

i have created a fold reagion, but this fold region is not colored in any way. I went into the settings and chose really bright colors, but its still not working:

 

If this helps, i added fold regions to the "DiffWindow" like this:

 

public class DiffWindowExtension extends DiffExtension {

@Override
public void onViewerCreated(FrameDiffTool.@NotNull DiffViewer viewer, @NotNull DiffContext context, @NotNull DiffRequest request) {
var left = ((SimpleDiffViewer) viewer).getEditor1();
var foldingModel = left.getFoldingModel();

foldingModel.runBatchFoldingOperation(() -> {
var foldRegion = foldingModel.createFoldRegion(
startOffset,
endOffset,
" ^--- THIS IS A PLACEHOLDER ---^ ",
FoldingGroup.newGroup(line + ""),
false
);
if (foldRegion != null) {
foldRegion.setExpanded(false);
foldRegion.setGutterMarkEnabledForSingleLine(true);
foldRegionList.add(foldRegion);
}
});
}

 

0

Do other folded regions in other files look blindingly red now?

0

I found the solution:

get the colorscheme, change it and then reapply it:

var colorsScheme = left.getColorsScheme();
colorsScheme.setAttributes(EditorColors.FOLDED_TEXT_ATTRIBUTES, new TextAttributes(JBColor.red, null, null, null, Font.BOLD));

left.setColorsScheme(colorsScheme);

 

0

Please sign in to leave a comment.