Codemirror onKeyEvent不触发 [英] codemirror onKeyEvent not firing
问题描述
我正在尝试让代码镜像显示提示功能,我已经设法使其与 extraKeys 一起使用,这可以很好地加载getHints函数,但是我真的希望它与 onKeyEvent ,但这似乎无能为力,我什至无法发送警报消息
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);
}
}
}
});
});
在这里,我正在玩的游戏我什至不知道我在做什么错,即使尝试使用jquery触发器似乎也无济于事:/ http://jsfiddle.net/f2n74k3s/7/
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/
推荐答案
onKeyEvent
在CodeMirror的API中不存在.因此,可以保证它不起作用.使用 extraKeys
,它是为此类任务而构建的.
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.
这篇关于Codemirror onKeyEvent不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!