如何在角度 ace 编辑器中根据特定场景启用和禁用默认代码段关键字



我在ace编辑器中使用片段。我创建了一些自定义代码段并将其添加到现有代码段中。但是我想在显示自定义代码段时隐藏默认代码段。如何仅在某些特定情况下禁用或隐藏默认代码段?

将自定义单词列表设为全局

self.customSnippets = ["A", "B']; //your array of default custom snippets  
 editor.commands.addCommand({
     name: "bindDot",
     bindKey: { win: ".", mac: "." },
         exec: function () {
             var position = editor.selection.getCursor();
             var session = editor.session;
             var currentLine = (session.getDocument().getLine(position.row)).trim();
             var currentTokens = currentLine.slice(0, position.column).split(/s+/);
             var currentCmd = currentTokens[0];
             if (!currentCmd) return;
             var lastToken = currentTokens[currentTokens.length - 1];
             var nextToken = currentTokens[currentTokens.length + 1];
             var filterValue = editor.session.getValue();
             if (filterValue === "") {
                 editor.insert(".");
             }
             if (lastToken === "page" || (lastToken.indexOf("page") > -1) || lastToken === "Page" || (lastToken.indexOf("Page") > -1) && (nextToken === "onAppVariablesReady" || (nextToken.indexOf("onAppVariablesReady") > -1)) {
                 editor.insert(".");
                 // Add your custom snipets to this global array
                 self.customSnippets = ["A", "B"];  // Global Array
             } else {
                 editor.insert(".");
             }
         }
   });

对于案例 2

editor.commands.addCommand({
    name: 'myCommand',
    bindKey: {win: 'Ctrl-Space',  mac: 'Command-Space'},
    exec: function(editor) {
        self.customSnippets = ["A", "B"]; //your array of default custom snippets
    }
});

相关内容

  • 没有找到相关文章

最新更新