Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ace编辑器的自动完成_Javascript_Objective C_Cocoa_Autocomplete_Ace Editor - Fatal编程技术网

Javascript Ace编辑器的自动完成

Javascript Ace编辑器的自动完成,javascript,objective-c,cocoa,autocomplete,ace-editor,Javascript,Objective C,Cocoa,Autocomplete,Ace Editor,好的,交易如下: var editor = ace.edit('editor'); editor.setTheme("ace/theme/eclipse"); editor.getSession().setMode("ace/mode/java"); editor.setShowInvisibles(true); editor.setDisplayIndentGuides(true); editor.getSession().setUseWrapM

好的,交易如下:

    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);
   [ {"word":"hello"}, 
   {"word":"good morning"},
   {"word":"suggestions"},
   {"word":"auto suggest"},
   {"word":"try this"}]
  • 我正在使用
  • 集成编辑器的应用程序是Objective-C/Cocoa编写的
  • 我需要自动完成(对于给定的一组关键字)
现在,这里有一个陷阱:

    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);
   [ {"word":"hello"}, 
   {"word":"good morning"},
   {"word":"suggestions"},
   {"word":"auto suggest"},
   {"word":"try this"}]
  • 我知道本机还不支持自动完成
  • 我知道其他人有一些尝试(例如),一些人利用了,但我仍然不知道如何将其适应现有的Ace设置
  • 我仍然不确定是应该使用面向JS的解决方案,还是仅仅使用Objective-C/Cocoa

任何帮助都将不胜感激。

自动完成最困难的部分是找出关键词,其余的都很容易做到

  • 您需要一个弹出窗口和listView来显示完成,它可能 最好使用基于可可粉的弹出窗口
  • 一些过滤功能,简单的startsWith check就可以了,但是你可以使用更好的flex匹配 像崇高
  • 调用editor.session.replace以插入 选定的完成

  • 对于2-3,您应该在评论您的特定用例,因为需要获得自动完成的本机支持。

    自动完成可以在ace编辑器中实现

    代码:

        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);
    
       [ {"word":"hello"}, 
       {"word":"good morning"},
       {"word":"suggestions"},
       {"word":"auto suggest"},
       {"word":"try this"}]
    
    Json文件格式:

        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);
    
       [ {"word":"hello"}, 
       {"word":"good morning"},
       {"word":"suggestions"},
       {"word":"auto suggest"},
       {"word":"try this"}]
    
    参考/演示:


    要在Ace中添加实时自动完成功能,请执行以下操作: 在HTML中包括ace/ext-language_tools.js。 这个调用还不能很好地工作,所以您可能必须为此输入ctrl空格或alt空格,但现在将显示标准语法内容,如writing函数。 然后:


    当嵌入到应用程序包装器中时,的可能副本对我不起作用。我必须使用
    editor.setOptions(“enableBasicAutocompletion”,true)。我认为这是应用程序包装器代理接口中的错误,而不是Ace中的错误。