如何在Ace Editor中指定自定义标记列表以列出自动完成功能? [英] How to specify a list of custom tokens to list for autocompletion in Ace Editor?
问题描述
在使用 Ace编辑器进行自动填充的设置之后,我可以使用 react-ace 。但是,我需要一些自定义标记才能在内置自动完成列表中使用。
After following the setup for autocompletion with Ace Editor, I have it working with react-ace. However, I need some custom tokens to be available in the built-in autocomplete list.
react-ace $ c $的存储库c>将这些属性定义为
enableBasicAutocompletion: PropTypes.oneOfType([PropTypes.bool, PropTypes.array]),
enableLiveAutocompletion: PropTypes.oneOfType([PropTypes.bool, PropTypes.array]),
但是这是 array
吗?
我尝试设置 enableBasicAutocompletion = {['custom'] }
和 enableBasicAutocompletion = {[(... args)=> console.log(args)]}
,但都失败,并显示有关 getCompletions而非函数的错误
。
I have tried setting enableBasicAutocompletion={ ['custom'] }
, and enableBasicAutocompletion={ [ (...args) => console.log(args) ] }
but both fails with an error about getCompletions not a function
.
如何将这些自定义自动填充关键字添加到列表中?
How can I add these custom autocomplete keywords to the list?
<AceEditor
name={ this.uniqueName }
mode="javascript"
theme="github"
onChange={ onChange }
enableBasicAutocompletion
enableLiveAutocompletion
/>
推荐答案
使用editor.completers数组添加一个新的完成器,返回您想要的补全
use editor.completers array to add a new completer that returns the completions you want
editor.completers.push({
getCompletions: function(editor, session, pos, prefix, callback) {
var completions = [];
// we can use session and pos here to decide what we are going to show
["word1", "word2"].forEach(function(w) {
completions.push({
value: w,
meta: "my completion",
});
});
callback(null, completions);
}
})
这篇关于如何在Ace Editor中指定自定义标记列表以列出自动完成功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!