在ace-editor中输入每个关键字后是否可以调用一个函数

Is it possible to call a function after typing each keyword in ace-editor

我想做的是在ace-editor中,每次输入完一个关键字,就可以自动调用一个函数。

例如,我在 ace-editor 中键入关键字 "new"。在我完成输入后,将调用警报功能并显示 "you have typed the keyword 'new'".

您可以使用更改侦听器或 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
            );
        }
    }
});