CodeMirror:foldAll还是unfoldAll from按钮



我希望在代码镜像文本区域周围有一些按钮,允许用户单击按钮即可打开foldAll或foldAll。这将避免他们不得不学习捷径。有可能吗?

以下是编辑器的定义(extraKeys按预期运行(:

var editor = CodeMirror.fromTextArea(document.getElementById("xmlViewer"), {
mode: "text/html",
lineNumbers: true,
tabMode: 'indent',
lineWrapping: true,
autoCloseTags: true,
height: "650px",
width: "90%",
parserfile: "parsexml.js",
stylesheet: "css/xmlcolors.css",
path: "js/",
continuousScanning: 500,
extraKeys: {
"Ctrl-Q": function (cm) { cm.foldCode(cm.getCursor()); },
"Alt-F": "findPersistent",
"Ctrl-Y": "foldAll",
"Ctrl-I": "unfoldAll"
},
foldGutter: true,
autoRefresh: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
});

以下是按钮的定义:

<input type="button" id="expandAllBtn" value="Expand All" class="btn btn-outline-primary btn-sm" />

以下是onclick的定义:

$("#collapseAllBtn").on("click", function (e) {
editor.foldAll; // nothing happens
//editor.foldAll(); // error not a function
//editor.commands.foldAll(); // cannot read property of undefined
//editor.commands.foldAll; // cannot read property of undefined
});

以下是实现这一点的方法:

$("#collapseAllBtn").on("click", function (e) {
editor.execCommand("foldAll");
});

最新更新