gpt4 book ai didi

autocomplete - Ace Editor Autocomplete - 两步自动完成

转载 作者:行者123 更新时间:2023-12-04 18:00:32 32 4
gpt4 key购买 nike

我正在尝试让 Ace Editor 支持我自己的查询语言的自动完成功能。

查询本身如下所示

city:newyork color:red color:blue

在上述情况下,我希望用户在输入“c”时可以看到“city”和“color”。而在他选择了‘颜色’之后,直接可以在建议列表中看到‘红’和‘蓝’两个选项。

我检查了 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
};
}));
}

请根据您的要求进行更改。

关于autocomplete - Ace Editor Autocomplete - 两步自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36128664/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com