Whats wrong? Fold gutters do not show up after swapDoc call

var initCM = function (data) {
    cmEditor = CodeMirror(document.getElementById('xmlresponse'), {
        lineNumbers: true,
        matchBrackets: true,
        styleActiveLine: true,
        theme: "neat",
        mode: 'xml',
        readOnly: false,
        extraKeys: {
            "F11": function (cm) {
                cm.setOption("fullScreen", !cm.getOption("fullScreen"));
            },
            "Esc": function (cm) {
                if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
            },
            "Ctrl-J": "toMatchingTag"
        },
        matchTags: {bothTags: true},            
        foldGutter: true,
        gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
    });
}
var handleXmlCode = function (data) {
    var indentedXml = $(data).serializeXmlDocument(true);
    cmDoc = CodeMirror.Doc(indentedXml, "xml");
    cmEditor.swapDoc(cmDoc);        
}

Above code is to show xml data in CM on each button click.
initCM() is called on document load. And handleXmlCode() is called from button click event.
When I click button first time it loads xml in editor and shows fold gutters. But in subsequent button clicks it doesnt show fold gutters. Remaining features like fullscreen, matchtags having no problem. Only fold gutters.

Do you think there is something wrong with my approach or code?

Here is gutter html that shows fold marker

<div class="CodeMirror-gutter-wrapper" style="left: -40px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">5</div><div class="CodeMirror-gutter-elt" style="left: 29px; width: 10px;"><div class="CodeMirror-foldgutter-open CodeMirror-guttermarker-subtle"></div></div></div>

Here is gutter html that doesn’t show fold marker

<div class="CodeMirror-gutter-wrapper" style="left: -40px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 21px;">5</div></div>

So, the missing elements are

<div class="CodeMirror-gutter-elt" style="left: 29px; width: 10px;"><div class="CodeMirror-foldgutter-open CodeMirror-guttermarker-subtle"></div></div>

Works for me. Try to submit a complete HTML file that shows the problem (without the extra styling, fullscreen, etc stuff), and I’ll take a look.

Here is html that can reproduce the issue. First click Xml1 button which will display xml as expected. then click Xml2 which will not display xml-fold-gutters/markers, but you still can expand/collapse xml nodes.

codemirror.html (4.6 KB)

Thanks, that file and those instructions do help reproduce it. I had tested only a single swapDoc call, but the problem was only showing up on the second one.

This patch should fix the problem.