2013-02-22 120 views
7

好了,所以这里的交易:自动完成的王牌编辑

  • 我使用Ace Editor
  • 该应用程序的编辑器被集成,是写的Objective-C /可可
  • 我需要AutoCompletion的(对于一个给定的关键字)

现在,这里的渔获:

  • 我知道的AutoCompletion还没有原生支持的
  • 我知道有些人试图通过他人(如Codiad IDEGherkinAlloy-UI),有的利用的Jquery UI Autocomplete - 但我仍然无法弄清楚如何能够适应现有的王牌设置
  • 我仍然不知道我是否应该去一个JS为导向的解决方案,或只是使用Objective-C/Cocoa那

任何帮助将不胜感激。

+0

可能重复(http://stackoverflow.com/questions/13545433/autocompletion-in-ace-editor) – endorama 2014-11-12 14:00:12

回答

17

的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

0

自动完成的难点在于找出关键字,其余部分很容易完成。

  1. 你需要一个弹出,和ListView显示的完成,它可能 更好地使用基于可可弹出。
  2. 一些过滤功能,简单startsWith检查都会做,但你可以使用更好的柔性匹配 像崇高
  3. 琐碎调用editor.session.replace插入 选择完成

2-3你应该在https://github.com/ajaxorg/ace/issues/110上评论您的特定用例,因为有一项工作可以获得对AutoCompletion的本机支持。

2

要王牌添加动态自动完成时下: 在你的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 
}); 
[自动完成在ACE编辑器]的
+0

嵌入时,我没有工作应用程序包装。我不得不使用'editor.setOptions(“enableBasicAutocompletion”,true);'。我认为这是应用程序包装代理接口中的一个错误,而不是Ace。 – 2015-07-31 15:04:55