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

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

问题描述

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

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天全站免登陆