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>