Search code examples
codemirror

CodeMirror readOnly allow paste from keyboard shortcut and mouse right click option


Im doing an app that will serve a purpose to teach class of students using codemirror plugin. The problem that i have is this, i dont want students to be able to change the code that im displaying for them in the editor, so i followed documentation and i have put readOnly property to true, this indeed disabled typing ability for them. But some smart student discovered that he can paste something to the editor using CTRL + V or right mouse click and selecting paste from it. Do you have idea how to put an end to that ?

this is an instance:

    var appCM = CodeMirror.fromTextArea(document.getElementById('app-cm'), {
        mode: 'text/html',
        theme: "monokai",
        styleActiveLine: true,
        lineNumbers: true,
        matchBrackets: true,
        indentUnit: 4,
        indentWithTabs: true,
        autoCloseTags: true,
        autoCloseBrackets: true,
        matchTags: false,
        extraKeys: {
            "Ctrl-Space": "autocomplete",
            "Ctrl-Q": function(appCM) {
                appCM.foldCode(appCM.getCursor());
            }
        },
        foldGutter: true,
        gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
        readOnly: true
    });

I have been reading this up but i havent find anything useful


Solution

  • This is a bug in version 5.5 that was fixed a few days ago (see this bug report). You can get the current development, apply the patch linked from that issue manually, or wait for the next release.