I tried to test the custom folding by the rangeFinder
function to foldOptions
(see below for setup), but it doesn’t work because onGutterClick function checks only the options of cm.state.foldGutter
(which doesn’t take the foldOptions
into account). How to do it right in a simple way, with restrictions as below?
My sample code executed on CodeMirror: Code Folding Demo page - pasted in dev console, also with test line <ref>test1</ref><ref>test2</ref><ref>test3</ref>
in editor_html window. I wanted (for testing purposes) to fold entire line into <ref>...</ref>
[to the first ref and the last ref]):
window.editor_html.options.foldOptions={
rangeFinder: (cm, pos) => {
var line=window.editor_html.getLine(pos.line);
var match=line.match(/<ref>(.*)<\/ref>/);
if (match==null) {
return CodeMirror.fold.auto(cm,pos);
}
else {
match=match[1];
var startPos=CodeMirror.Pos(pos.line, match.index);
var endPos=CodeMirror.Pos(pos.line, match.index+match.length);
return endPos && CodeMirror.cmpPos(endPos, startPos) > 0 ? {from: startPos, to: endPos} : null;
}
}
}