codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.91k stars 376 forks source link

Unable to create an EditorState #138

Closed arguiot closed 5 years ago

arguiot commented 5 years ago

I want to create an EditorState, using this code:

EditorState.create({
    doc: atobUTF8(value),
    extensions: [
        lineNumbers(),
        history(),
        specialChars(),
        multipleSelections(),
        mode,
        // matchBrackets(),
        keymap({
            "Mod-z": undo,
            "Mod-Shift-z": redo,
            "Mod-u": function(view) {
                return undoSelection(view) || true
            },
            [isMac ? "Mod-Shift-u" : "Alt-u"]: redoSelection,
            "Ctrl-y": isMac ? undefined : redo,
            "Shift-Tab": indentSelection
        }),
        keymap(baseKeymap),
    ]
})

But, for some reasons, I'm getting this error:

TypeError: field of state.behavior is not a function

I strongly think it's related to what state.behavior is outputting: on the following image, you can see that I get the Boolean true when I run state.behavior(stateField), while it should be an iterable object (like an array or a JSON object)

Capture d’écran 2019-11-14 à 18 09 14

Here is where the debugger is stopping:

https://github.com/codemirror/codemirror.next/blob/7cbbe0105c044aea586252f94afb106ca5022b46/state/src/state.ts#L133

marijnh commented 5 years ago

Which version of the code are you running? And how are you building the library? The for (var state of ...) in your debugger looks a little strange—why is the let compiled to var but the of-loop still in there?

arguiot commented 5 years ago

I’m using the latest version (master), and here is my rollup config:

export default {
    input: "./lib.js",
    output: {
        format: "umd",
        file: "../StudIO/Editor/CodeMirror/EditorView/libCM.js",
        sourcemap: false,
        name: "StudIO"
    },
    plugins: [
        resolve(),
        commonjs()
    ]
}

After that, I also replace as you saw all let with var because I wanted to make the code run on older browser... Not sure this part is useful now, so I might remove that.

arguiot commented 5 years ago

Actually, you were right, thanks, it resolves this issue (so I'll mark it as closed), but I'm now getting another error when I'm creating the EditorView

Error: Non-view extensions found in view
marijnh commented 4 years ago

Error: Non-view extensions found in view

I guess this means that either you are passing a state extension when creating an EditorView, or you somehow have multiple instances of the view package loaded, and an extension that targets one of them is loaded in another.

arguiot commented 4 years ago

Apparently, the issue is with legacyMode, as I pass the mode to EditorState as an extension.

I create the mode using:

let mode = legacyMode({
    mode: m
})

where m is the export of a legacy mode

marijnh commented 4 years ago

No legacyMode function exists in the current codebase, though.

arguiot commented 4 years ago

I think that the legacyMode function that I’m importing is from an old commit, but the js file was kept because it wasn’t part of the repository... anyway.

Is there a similar function I can use for importing all modes to CM6?

marijnh commented 4 years ago

Is there a similar function I can use for importing all modes to CM6?

As things stand, modes have to be at least superficially ported to work with the stream-syntax package. You can find some examples in the legacy-modes directory.