我想做的是,在ace编辑器中,每次输入关键字时,都可以自动调用函数。
例如,我在ace-编辑器中键入关键字"new“。在我完成输入之后,将调用一个警报函数,并说“您输入了关键字'new'”。
发布于 2015-05-29 07:08:31
您可以使用更改侦听器或beforeEndOperation侦听器,并使用以下内容
editor.on("beforeEndOperation", function(e) {
if (editor.curOp.docChanged && editor.curOp.command.name == "insertstring") {
var pos = editor.getCursorPosition();
var token = editor.session.getTokenAt(pos.row, pos.column);
if (token && token.type == "keyword") {
alert(
"Hey there!",
"This is me, the most annoying editor feature evar.",
"Just wanted to let you know, that you have typed a keyword",
token.value
);
}
}
});https://stackoverflow.com/questions/30517285
复制相似问题