2016-03-21 169 views
1

我想讓Ace Editor支持自動完成自己的查詢語言。王牌編輯器自動完成 - 兩步自動完成

查詢本身是一樣的東西下面

city:newyork color:red color:blue 

在上述情況下,我希望用戶可以看到「城市」和「顏色」鍵入「C」時。在選擇「顏色」後,他可以在建議列表中直接看到「紅色」和「藍色」這兩個選項。

我檢查了getCompletions的所有參數:函數(編輯器,會話,pos,前綴,回調)。但仍然無法找出更好的方法來做到這一點。任何建議將不勝感激。

回答

0

這不可能直接或通過ace編輯器默認自動完成。 但我有可能完全滿足您的要求的示例代碼。 第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 
     }; 
    })); 
} 

請改按你的要求。