自定义自动填充程序和期间(。) [英] Custom autocompleter and periods (.)

查看:77
本文介绍了自定义自动填充程序和期间(。)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用自定义前缀提取正则表达式 identifierRegexps

I can't seem to make getCompletions function to trigger in my custom completer when using custom prefix extraction regex identifierRegexps

基本上,我正在尝试创建一个自动填充器,该自动填充器将在以字母开头的句点(。)上触发。例如。在 foo中。

Basically I am trying to create an autocompleter which will trigger on periods (.) preceded by letters. E.g. In "foo." when the period is typed I would like to present my custom suggestions.

var lang = ace.require("ace/ext/language_tools");
var editor = ace.edit("editor");
editor.getSession().setMode("ace/mode/javascript");
editor.setOptions({
  enableBasicAutocompletion: true,
  enableSnippets: true,
  enableLiveAutocompletion: true
});

var compl = {
  identifierRegexps: [/[a-zA-Z_0-9\.\$\-\u00A2-\uFFFF]/],
  getCompletions: function (editor, session, pos, prefix, callback) {
    alert(prefix);

    callback(null, []);
    return;
  }
}
lang.addCompleter(compl);

使用上述代码段,在输入点但 getCompletions 时会弹出建议弹出窗口不会触发。但是,它确实会触发其他任何字符。

With the above snippet, suggestions popup appears when typing a dot but getCompletions doesn't trigger. However, it does trigger on any other character.

更新:

删除默认的完成者,然后添加

Removing default completers prior to adding the custom one with

lang.setCompleters();

触发 getCompletion 函数。但是 prefix 参数在这种情况下为空。

makes the getCompletion function to trigger. However prefix argument is empty in that case.

推荐答案

设法通过修改ID_REGEX变量来解决它在language_tools.js中。

Managed to solve it by modifying the ID_REGEX var in language_tools.js.

这篇关于自定义自动填充程序和期间(。)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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