Ace Editor Autocomplete - 两步自动完成
Ace Editor Autocomplete - two steps autocomplete
我正在尝试让 Ace Editor 支持我自己的查询语言的自动完成。
查询本身如下所示
city:newyork color:red color:blue
在上述情况下,我希望用户在键入 'c' 时可以看到 'city' 和 'color'。而他选择'color'后,直接可以在建议列表中看到'red'和'blue'两个选项。
我检查了 getCompletions: function(editor, session, pos, prefix, callback) 的所有参数。但仍然无法找出更好的方法来做到这一点。任何建议将不胜感激。
无法直接或通过 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
};
}));
}
请根据您的要求进行更改。
我正在尝试让 Ace Editor 支持我自己的查询语言的自动完成。
查询本身如下所示
city:newyork color:red color:blue
在上述情况下,我希望用户在键入 'c' 时可以看到 'city' 和 'color'。而他选择'color'后,直接可以在建议列表中看到'red'和'blue'两个选项。
我检查了 getCompletions: function(editor, session, pos, prefix, callback) 的所有参数。但仍然无法找出更好的方法来做到这一点。任何建议将不胜感激。
无法直接或通过 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
};
}));
}
请根据您的要求进行更改。