简体   繁体   English

在Codemirror中显示行错误?

[英]Show line errors in codemirror?

I just upgraded CodeMirror to latest and have the following code now breaking: 我刚刚将CodeMirror升级到最新版本,并且现在破坏了以下代码:

        // clear previous errors from editor window
        for (var i = 0; i < layoutCodeEditor.lineCount(); i++) {
            layoutCodeEditor.clearMarker(i);
            layoutCodeEditor.setLineClass(i, null, null);
        }

        var valid = JSLINT(code);
        var jsLintError = "";
        if (!valid) {
            jsLintError = JSLINT.error_report(JSLINT.data());
            _.chain(JSLINT.errors).compact().each(function(e){
                // show markers in the code edit window against lines with Jslint errors
                layoutCodeEditor.setMarker((+e.line) - 1, "●", "errors");
                layoutCodeEditor.setLineClass(+(e.line) - 1, null, "errorLine");                    
            })
        }

seems like the setMarker/clearMarker and setLineClass functions have been removed. 似乎setMarker / clearMarker和setLineClass函数已被删除。 What's their equivalents now? 现在相当于什么?

These changes, among many others, are covered in the Upgrading to version 3 page on the CodeMirror site. 这些更改以及许多其他更改,在CodeMirror站点的“ 升级到版本3”页面中进行了介绍。

The marker functions have changed as a consequence of moving to multiple gutters: 移动到多个装订线的结果是标记功能发生了变化:

Gutter model 天沟模型

In CodeMirror 2.x, there was a single gutter, and line markers created with setMarker would have to somehow coexist with the line numbers (if present). 在CodeMirror 2.x中,只有一个装订线,并且使用setMarker创建的行标记必须以某种方式与行号共存(如果存在)。 Version 3 allows you to specify an array of gutters, by class name , use setGutterMarker to add or remove markers in individual gutters, and clear whole gutters with clearGutter . 版本3允许您通过类名称指定一组setGutterMarker ,使用setGutterMarker在单个setGutterMarker中添加或删除标记,并使用clearGutter清除整个clearGutter Gutter markers are now specified as DOM nodes, rather than HTML snippets. 装订线标记现在指定为DOM节点,而不是HTML代码段。

The gutters no longer horizontally scrolls along with the content. 装订线不再随内容一起水平滚动。 The fixedGutter option was removed (since it is now the only behavior). fixedGutter选项已删除(因为现在是唯一的行为)。

The line class change is more straightforward: 行类的更改更为简单:

Line CSS classes 行CSS类

The setLineClass method has been replaced by addLineClass and removeLineClass , which allow more modular control over the classes attached to a line. setLineClass方法已由addLineClassremoveLineClass代替,它们允许对附加到行的类进行更多的模块化控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM