ace editor autocomplete启用

myEditor.setOptions({
        enableBasicAutocompletion: true,
        enableSnippets: true,
        enableLiveAutocompletion: true
    });

var
autoCompleteData = [{ "meta": "function", "caption": "addShape", "value": "addShape", "score": 1 }, { "meta": "function", "caption": "addShape.adc", "value": "addShape.adc", "score": 1 }, { "meta": "function", "caption": "addShape.ccc", "value": "addShape.ccc", "score": 1 }]; var tangideCompleter = { getCompletions: function (editor, session, pos, prefix, callback) { if (prefix.length === 0) { return callback(null, []); } else { return callback(null, autoCompleteData); } } } var langTools = ace.require("ace/ext/language_tools"); langTools.addCompleter(tangideCompleter);

最近做一个python在线策略,决定用ace editor,启用autocomplete方便编写python。

要引入ext/language_tools,添加completer,自定义的关键字格式是{ "meta": "function", "caption": "addShape", "value": "addShape", "score": 1 }。

如果要dot后面增加类似类的属性的autocomplete,需修改ext-language_tools中的ID_REGEX = /[a-zA-Z_0-9\$-\$.]/;

js中增加

myEditor.commands.on("afterExec", function (e, t) {
        if (e.command.name == "insertstring" && e.args == ".") {
            var all = e.editor.completers;
            //e.editor.completers = completers;
            e.editor.execCommand("startAutocomplete");
            e.editor.completers = all;
        }
    });

转载于:https://www.cnblogs.com/hyfwin/p/5569293.html

你可能感兴趣的:(ace editor autocomplete启用)