简体   繁体   中英

auto-completion in ace.js editor

I would like to know if it's possible to enable auto-completion while user is typing in editor ace.js. At the moment in my project auto-completion is enabled when user type: ctrl + space . Then, is possible adding some keywords in the auto-completion list?

Thanks

For triggering autocomplete use

editor.commands.on("afterExec", function(e){
     if (e.command.name == "insertstring"&&/^[\w.]$/.test(e.args)) {
         editor.execCommand("startAutocomplete")
     }
})

For addidng some keywords you can either add another completer to the editor or override getCompletions method on the mode.

It's already built in! See the options that I chose under editor.setOptions :

    var langTools = ace.require("ace/ext/language_tools");
    var editor = ace.edit("editor");

    editor.setTheme("ace/theme/monokai");
    editor.getSession().setMode("ace/mode/yaml");

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM