javascript ACE 编辑器自动完成 - 自定义字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30041816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ACE Editor Autocomplete - custom strings
提问by russtuck91
I'm using ACE Editor within a Chrome extension. I'm using ACE's Autocomplete feature but I want to be able to completely define a list of static strings to use for the autocomplete, instead of any local strings or snippets. (In the future I might be using something more sophisticated than a static list, but for now static is fine.)
我在 Chrome 扩展程序中使用 ACE 编辑器。我正在使用 ACE 的自动完成功能,但我希望能够完全定义用于自动完成的静态字符串列表,而不是任何本地字符串或片段。(将来我可能会使用比静态列表更复杂的东西,但现在静态很好。)
Can anyone provide some instruction on how to accomplish this? I already have autocomplete enabled and snippets off, but I'm having trouble defining a static list of strings to use.
任何人都可以提供一些有关如何完成此操作的说明吗?我已经启用了自动完成功能并关闭了代码片段,但是我无法定义要使用的静态字符串列表。
All I have so far is:
到目前为止我所拥有的是:
var editor = ace.edit('propertiesText');
editor.getSession().setMode('ace/mode/properties');
var langTools = ace.require('ace/ext/language_tools');
// code here to define custom strings?
editor.setOptions({
enableBasicAutocompletion: true
});
回答by a user
you need to add a completer like this
你需要添加一个像这样的完成者
var staticWordCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
var wordList = ["foo", "bar", "baz"];
callback(null, wordList.map(function(word) {
return {
caption: word,
value: word,
meta: "static"
};
}));
}
}
langTools.setCompleters([staticWordCompleter])
// or
editor.completers = [staticWordCompleter]
回答by annakula achyuth
If you want to persist the old keyword list and want to append a new list
如果你想保留旧的关键字列表并想追加一个新的列表
var staticWordCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
var wordList = ["foo", "bar", "baz"];
callback(null, [...wordList.map(function(word) {
return {
caption: word,
value: word,
meta: "static"
};
}), ...session.$mode.$highlightRules.$keywordList.map(function(word) {
return {
caption: word,
value: word,
meta: 'keyword',
};
})]);
}
}
langTools.setCompleters([staticWordCompleter])
// or
editor.completers = [staticWordCompleter]