2016-03-21 12 views
1

私自身のクエリ言語用のAce Editorサポートオートコンプリートを作成しようとしています。Aceエディタのオートコンプリート - 2ステップオートコンプリート

クエリ自体は、上記の場合

city:newyork color:red color:blue 

以下のようなものですが、私は「C」を入力するときにユーザーが「都市」と「色」を見ることができます期待しています。また、「色」を選択すると、候補リストに「赤」と「青」の2つのオプションが直接表示されます。

getCompletions:function(editor、session、pos、prefix、callback)の引数をすべて確認しました。しかし、これを行うためのより良い方法をまだ理解できません。どんな提案も感謝します。

答えて

0

直接編集することはできません。 しかし、私はあなたの要件を満たすことができるサンプルコードを持っています。 ステップ-1: エディタオブジェクトとセットオプションを作成する必要があります。

ace.require("ace/ext/language_tools"); 
    var editor = ace.edit('div_id'); 
    editor.setTheme("ace/theme/textmate"); 
    editor.getSession().setMode("ace/mode/yaml"); 
    editor.getSession().setTabSize(4); 
    editor.getSession().setUseSoftTabs(true); 
    editor.setDisplayIndentGuides(true); 
    editor.setShowInvisibles(true); 
    editor.setShowPrintMargin(false); 
    editor.setOption("vScrollBarAlwaysVisible", true); 
    editor.setOptions({ 
     enableBasicAutocompletion: true, 
     enableLiveAutocompletion: true 
    }); 


var EditorWordCompleter = { 
    getCompletions: function(editor, session, pos, prefix, callback) { 
     getWordList(editor, session, pos, prefix, callback); 
     } 
    } 

var getWordList = function(editor, session, pos, prefix, callback) { 
    var wordList = []; 
    if(prefix === 'T') { 
     wordList.push('List of tasks'); 
    } 
    wordList = $.unique(wordList); 
    callback(null, wordList.map(function(word) { 
     return { 
      caption: word, 
      value: word 
     }; 
    })); 
} 

あなたが要件だに従って、それを変更してください。

関連する問題