custom fold code in merge view

I want to custom fold code in merge view, but it seems not work in merge view mode. Anyone can help me?Here is my code:

import 'codemirror/lib/codemirror.css';
import 'codemirror/addon/merge/merge.js';
import 'codemirror/addon/merge/merge.css';
import 'codemirror/addon/selection/mark-selection.js';
import 'codemirror/addon/scroll/simplescrollbars.js';
import 'codemirror/addon/scroll/simplescrollbars.css';
import 'codemirror/addon/scroll/annotatescrollbar.js';
import 'codemirror/addon/fold/foldcode.js';
import 'codemirror/addon/fold/foldgutter.js';
import 'codemirror/addon/fold/foldgutter.css';

this.codeMirrorOptions = {
        connect: 'align',
        value: this.rightSideData, 
        origRight: null,
        origLeft: this.leftSideData,
        lineNumbers: true, 
        readOnly: this.options.readOnly, 
        styleSelectedText: true, 
        inputStyle: 'contenteditable',
        showDifferences: true,
        scrollbarStyle: this.scrollbarType,
        foldGutter: true,
        gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
        extraKeys: {
          U: () => {
            this.goBack();
          },
          '[': () => {
            this.page('pre');
          },
          ']': () => {
            this.page('next');
          },
        },
      },
this.Editor = CodeMirror.MergeView(this.target, this.codeMirrorOptions);
this.Editor.foldCode(CodeMirror.Pos(0, 0))

By the way, I want to custom fold code in merge view with code diff and linewidget which exclude these in code folder like Gerrit code reivew system, but I have no idea how to accomplish it.

It’s not entirely clear what you’re trying to do, but you don’t seem to be loading or defining any fold logic or language mode in that code, which would indeed prevent any folding from happening.

Hi, marigin, thanks for your help! I’m sorry, my description of the problem not clear,I try to explain to clear my problem.
Does code folding have to pass in language mode? Is it possible to fold code based on a custom line count independent of the language? And the folding logic you mentioned, I understand it to call foldCode api to fold code.

Check the manual. You can either pass a custom range finder function to the code folding addon, or rely on “helpers” defined in files like addon/fold/brace-fold.js , and referenced by language modes that use that kind of structure (for example the JavaScript mode will declare that the brace folder can be used when it is active).

Thanks a lot, I’ll look into it

Hi marijn, I come to bother you again! I called the rangeFinder function, successfully implemented the custom folded column and called the widget function, and customized the foldmarker, but the foldmarker was inserted at the end of the folded start line and became an inline element. I want to insert it into the next line of the folded start line Just like a linewidget, I can’t think of a better way than manually changing the dom structure. Is there a good way to insert the foldmarker into the start line and the next line?