好的,所以这是交易:
>我正在使用Ace Editor
>编辑器集成的应用程序,是Objective-C/C++ocoa
>我需要AutoCompletion(针对给定的一组关键字)
现在,这是一个问题:
>我知道AutoCompletion尚未得到本机支持
>我知道其他人的尝试(例如Codiad IDE,Gherkin,Alloy-UI),有些尝试使用Jquery UI Autocomplete – 但我仍然无法弄清楚如何将其改编为现有的Ace设置
>我仍然不确定我是否应该选择面向JS的解决方案,或者只是使用Objective-C/C++ocoa
任何帮助都不仅仅是值得赞赏的.
解决方法
可以在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);
Json文件格式:
[ {"word":"hello"},{"word":"good morning"},{"word":"suggestions"},{"word":"auto suggest"},{"word":"try this"}]
参考/演示:
http://plnkr.co/edit/6MVntVmXYUbjR0DI82Cr?p=preview