本文介绍了CodeMirror foldCode方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写在线编辑器,此刻正在尝试实现代码折叠。他们在CodeMirror网站上进行了演示,该演示使用了来自foldcode.js插件的foldCode命令。

这是我的代码。

I am trying to write an online editor and at the moment am trying to implement code folding. On the CodeMirror website they do a demo that uses the foldCode command that comes from the foldcode.js addon.
Here is my code.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Code Mirror Test</title>
    <script type="text/javascript" src="codemirror-5.4/lib/codemirror.js"></script>
    <link rel="stylesheet" href="codemirror-5.4/lib/codemirror.css">
    <link rel="stylesheet" href="codemirror-5.4/theme/neat.css">
    <script type="text/javascript" src="codemirror-5.4/mode/javascript/javascript.js"></script>
    <link rel="stylesheet" href="src/Main.css">
    <script type="type/javascript" src="codemirror-5.4/addon/fold/foldcode.js"></script>
    <script type="type/javascript" src="codemirror-5.4/addon/fold/foldgutter.js"></script>
    <link rel="stylesheet" href="codemirror-5.4/addon/fold/foldgutter.css">

</head>
<body>
    <script>
        window.onload = function() {
            var editor = CodeMirror(document.body, {
                mode: "javascript",
                lineNumbers: true,
                theme: "neat",
                extraKeys: {"Ctrl-Q": function(cm) { cm.foldCode(cm.getCursor()); }},
                foldgutter: true,
                gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
            });
        }

    </script>
</body>
</html>

IntelliJ告诉我foldCode是一个未解决的方法。我想知道我导入的脚本是否错误,或者foldCode是否已被CodeMirror的最新版本贬值?

IntelliJ is telling me that foldCode is an unresolved method. Im wondering if maybe I am importing the script wrong or may be foldCode was depreciated with the newest versions of CodeMirror?

推荐答案

似乎没有加载任何实际的折叠功能。对于JavaScript,您可能需要 addon / fold / brace-fold.js

You don't seem to be loading any actual folding functions. For JavaScript, you probably want addon/fold/brace-fold.js.

这篇关于CodeMirror foldCode方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 16:12