codemirror onKeyEvent not firing

泪湿孤枕 提交于 2021-02-10 23:51:23

问题


I am trying to get codemirrors show hint functionality to work I have managed to get it to work with extraKeys this loads the getHints function fine but I really want it to work with onKeyEvent but this doesn't seem to do anything I can't even get it to send an alert message

function getHints(cm) {
// find the words
}

$(document).ready(function(){
CodeMirror.registerHelper("hint", "logger", getHints);
CodeMirror.commands.autocomplete = function(cm) {
    cm.showHint({hint: CodeMirror.hint.logger});
  }
var editor = CodeMirror.fromTextArea(
    $("#log").get(0),
    {
        extraKeys: {"Ctrl": "autocomplete"},
        onKeyEvent: function(e, s) {
                var kc = s.keyCode;
                if (s.type == "keyup") {
                    if (kc != 38 && kc != 40 && kc != 13 && kc != 27 && kc != 32) {
                        alert(kc);
                        CodeMirror.commands.autocomplete(e);
                    }
                }
            }
    });
});

Heres what I was playing with I have no idea what I am doing wrong even trying to use jquerys trigger doesnt seem to do anything :/ http://jsfiddle.net/f2n74k3s/7/


回答1:


onKeyEvent does not exist in CodeMirror's API. Hence, it is guaranteed not to work. Use extraKeys, it is built for this kind of task.



来源:https://stackoverflow.com/questions/29291024/codemirror-onkeyevent-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!