1

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 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?

Jack
  • 501
  • 3
  • 10

3 Answers3

5

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

Marijn
  • 8,691
  • 2
  • 34
  • 37
1

Besides the other answers, add

editor.foldCode(CodeMirror.Pos(0, 0));

outside of your var editor

Juan Serrats
  • 1,358
  • 5
  • 24
  • 30
MShivam
  • 11
  • 2
0

change

foldgutter: true;

to

foldGutter: true;
NilsB
  • 1,154
  • 1
  • 16
  • 42