首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ace-Editor忽略/将某些标记/字符串列入白名单

Ace-Editor忽略/将某些标记/字符串列入白名单
EN

Stack Overflow用户
提问于 2018-08-06 19:31:03
回答 1查看 73关注 0票数 0

如果我使用像<#input“asd”>这样的标签,有没有办法避免Ace-Editor抛出错误?就像白名单建议AceEditor忽略它...无论如何,它是一个内部键,我无法避免使用它。我正在使用react。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-08-07 02:31:58

我想有两种方法来解决这个问题:

1)也许你可以绑定">",获取最后输入的值,然后清除错误:

代码语言:javascript
复制
editor.commands.addCommand({
    name: "dotCommand1",
    bindKey: { win: ".", mac: "."},
    exec: function () {
        var pos = editor.selection.getCursor();
        var session = editor.session;

        var curLine = (session.getDocument().getLine(pos.row)).trim();
        var curTokens = curLine.slice(0, pos.column).split(/\s+/);

        //You can build a logic using the curTokens array and then when you find <#input "asd"> clear the errors.

        // If we assume curTokens[0] to have the value  

        if(curTokens[0] === '<#input "asd">') {
            editor.session.setAnnotations([]); // This would remove the being shown error
        }            
    }
});

2)使用on change事件并使用上面类似的逻辑,然后清除错误

代码语言:javascript
复制
editor.getSession().on('change', function () {
    // same logic as above
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51706639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档