我使用ace编辑器为自定义片段启用自动填充功能我已通过某种方法加载到ace / snippets中。但是,我希望只有在用户键入正确的范围然后触发所述片段后,才会在自动完成中弹出各种片段。
目前,我在片段中设置了正则表达式的警卫,但这似乎没有用。 Example of what a loaded snippet object looks like
防护功能是否足够有效地触发片段或我是否必须修改ace.define函数中的某些内容?
var editor = ace.edit("aceTextEditorContainer");
editor.setTheme("ace/theme/textmate");
editor.getSession().setMode("ace/mode/gameblox");
ace.require("ace/config").set("workerPath", "path/to/ace");
// editor.session.setOption("useWorker", true);
ace.require("ace/ext/language_tools");
editor.$blockScrolling = Infinity;
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
我目前有这个。 我通过这个函数加载片段:
ace.config.loadModule("ace/snippets/gameblox", function() {
if (window.snippetArray) {
snippetManager.files.gameblox = {};
snippetManager.files.gameblox["scope"] = "gameblox";
snippetManager.files.gameblox["snippetText"] = ace.require("ace/snippets/gameblox").snippetText;
snippetManager.files.gameblox["snippets"] = [];
snippetManager.files.gameblox.snippets.concat(ace.require("ace/snippets/gameblox").snippets);
for (var i=0; i<window.snippetArray.length; i++){
var m = window.snippetArray[i].name;
if (window.snippetArray[i].arguments){
m += window.snippetArray[i].arguments;
}
var f = snippetArray[i].function;
if (window.snippetArray[i].possibleScopes){
var sGuard = snippetArray[i].possibleScopes;// + "[.]" + f;
var sScope = "scope:gameblox \n\ \n\ WWWuuuutttt \n\ snippet "+m +" \n\ "+ f+ " \n\ ";
snippetManager.files.gameblox.snippetText += sScope;
var aScope = {name:m,content:f, trigger:sGuard + "[.]" + f.split("(")[0]};//,tabTrigger:sGuard,guard:sGuard, trigger:sGuard, endTrigger:sGuard, endGuard: sGuard};
snippetManager.files.gameblox.snippets.push(aScope);
} else {
var sNoScope = "scope:gameblox \n\ \n\ WWWuuuutttt \n\ snippet "+m +" \n\ "+f + " \n\ ";
snippetManager.files.gameblox.snippetText += sNoScope;
var a = {name:m,content:f,tabTrigger:f};
snippetManager.files.gameblox.snippets.push(a);
}
}
snippetManager.register(snippetManager.files.gameblox.snippets, snippetManager.files.gameblox.scope);
}
});
例如,我希望在下面链接的图片中的片段仅在编辑器中输入相应的实体/范围时出现。适当的范围不是静态的,并且会根据用户生成的内容定期更新,因此硬编码不是一种选择。 现在,无论如何都会弹出。 Example of autocomplete 任何帮助将不胜感激!
谢谢。