Search code examples
javascriptcodemirror

How to stop CodeMirror from moving cursor on keyup?


I want to skip certain, uneditable (XML-)tags in my code, using CodeMirror. In order to do that, I have to 'stop' (preventDefault) the keyup event, do some logic and move the cursor. PreventDefault and codemirrorIgnore don't work or do not do what I need them to do. Do I have to catch the event outside CodeMirror? :(

Does not work:

codeMirror.on('keyup', function (cm, ev) { ev.codemirrorIgnore = true; ev.preventDefault(); return false; });


Solution

  • By using the below code you can handle the up arrow functionality

    codeMirror.setOption("extraKeys", {"Up":function()
    {
     console.log("Key Up pressed");
    if(true) // logic to decide whether to move up or not
    {
     return CodeMirror.PASS;
    }
    }});