Ace编辑器的自动完成功能

Dr.*_*eon 8 javascript cocoa autocomplete objective-c ace-editor

好的,所以这是交易:

  • 我正在使用Ace编辑器
  • 编辑器集成的应用程序是Objective-C/Cocoa
  • 我需要AutoCompletion(对于给定的一组关键字)

现在,这里有一个问题:

  • 我知道AutoCompletion尚未得到本机支持
  • 我知道其他人的一些尝试(例如Codiad IDE,Gherkin,Alloy-UI),有些尝试使用Jquery UI Autocomplete - 但我仍然无法弄清楚如何将其改编为现有的Ace设置
  • 我仍然不确定我是否应该选择面向JS的解决方案,或者只是使用Objective-C/Cocoa

任何帮助都不仅仅是值得赞赏的.

小智 19

可以在ace编辑器中实现AutoCompletion ..

代码:

    var editor = ace.edit('editor');
    editor.setTheme("ace/theme/eclipse");
    editor.getSession().setMode("ace/mode/java");
    editor.setShowInvisibles(true);
    editor.setDisplayIndentGuides(true);
    editor.getSession().setUseWrapMode(true);    
    var jsonUrl = "JSON/Components/proce.json";
    //the url where the json file with the suggestions is present
    var langTools = ace.require("ace/ext/language_tools");
    editor.setOptions({enableBasicAutocompletion: true});
    var rhymeCompleter = {
        getCompletions: function(editor, session, pos, prefix, callback) {
            if (prefix.length === 0) { callback(null, []); return }
            $.getJSON(jsonUrl, function(wordList) {
                callback(null, wordList.map(function(ea)  {           
                    return {name: ea.word, value: ea.word, meta: "optional text"}
                }));
            })
        }
    }

    langTools.addCompleter(rhymeCompleter);
Run Code Online (Sandbox Code Playgroud)

Json文件格式:

   [ {"word":"hello"}, 
   {"word":"good morning"},
   {"word":"suggestions"},
   {"word":"auto suggest"},
   {"word":"try this"}]
Run Code Online (Sandbox Code Playgroud)

参考/演示:

http://plnkr.co/edit/6MVntVmXYUbjR0DI82Cr?p=preview


mes*_*ros 5

现在要在Ace中添加实时自动完成功能:在您的HTML中包括ace / ext-language_tools.js。的。调用尚无法正常运行,因此您可能必须为此输入ctrl-space或alt-space,但是现在将显示标准语法内容,例如写函数。然后:

var editor = ace.edit("editor");

ace.require("ace/ext/language_tools");
editor.setOptions({
    enableBasicAutocompletion: true,
    enableSnippets: true,
    enableLiveAutocompletion: true
});
Run Code Online (Sandbox Code Playgroud)