ACE编辑器自动完成 - 自定义字符串 [英] ACE Editor Autocomplete - custom strings

查看:1035
本文介绍了ACE编辑器自动完成 - 自定义字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Chrome扩展程序中使用了ACE编辑器。我正在使用ACE的自动完成功能,但我希望能够完全定义用于自动完成的静态字符串列表,而不是任何本地字符串或片段。 (将来我可能会使用比静态列表更复杂的东西,但现在静态是好的。)

任何人都可以提供关于如何完成此操作的指导吗?我已经启用了自动完成功能并关闭了代码片断,但是我无法定义要使用的静态字符串列表。



到目前为止,我所拥有的是:

  var editor = ace.edit('propertiesText'); 
editor.getSession()。setMode('ace / mode / properties');
var langTools = ace.require('ace / ext / language_tools');

//在此处定义自定义字符串的代码?

editor.setOptions({
enableBasicAutocompletion:true
});


解决方案

您需要添加一个像这样的完成者

  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
};
}));



$ b langTools.setCompleters([staticWordCompleter])
//或
editor.completers = [staticWordCompleter]


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.)

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
});

解决方案

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]

这篇关于ACE编辑器自动完成 - 自定义字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆