【问题标题】:Ace Editor: Can't get rid of Marker王牌编辑器:无法摆脱标记
【发布时间】:2015-10-24 23:14:07
【问题描述】:

我正在编写一个简单的小部件来模拟一个简单的 8 位 CPU。为此,我滥用了 Ace 编辑器,正如您在图像中心看到的那样,作为我的“RAM”视图。

我想突出显示与程序计数器的值相对应的行,我正在使用addMarker() 这样做。

但是,一旦我设置了那个标记,我似乎无法摆脱它。 _marker 是一个私有成员,它保存最后一个标记集的值。但是由于某种原因removeMarker(_marker) 没有效果:

/**
 *
 */
setMarker: function(position) {

    //if(_marker != null) {
        window.cpuRamView.session.removeMarker(_marker);
    //}

    _marker = new window.Range(position, 0, position, _content[position].length);

    window.cpuRamView.session.addMarker(
        _marker, "programCounterLocation", "fullLine"
    );
}

我在这里做错了什么? :/

【问题讨论】:

  • 你完成了那个项目吗?听起来很有趣。
  • @AdrianMoisa 嗯,是的,我完成了它,但我认为我找不到这个项目——它只是为了在大学里做练习。但是,如果您知道如何将代码转换为字节码并且对程序集或 cpu 的工作原理有一些基本知识,那么让类似的东西运行起来相当简单。

标签: javascript ace-editor


【解决方案1】:

添加标记返回一个id,而removeMarker需要那个id,所以你可以做类似

var Range = require("ace/range").Range // not the window Range!!
var _range

setMarker = function(position) {

    if(_range != null) {
        window.cpuRamView.session.removeMarker(_range.id);
    }

    _range = new Range(position, 0, position, _content[position].length);

    _range.id = window.cpuRamView.session.addMarker(
        _range, "programCounterLocation", "fullLine"
    );
}

【讨论】:

    【解决方案2】:
    if(this.marker) {
            this.editor.getSession().removeMarker(this.marker);
          }
          this.marker = this.editor.getSession().addMarker(
            new Range(prop('errorLine')(formulaError), prop('errorPosition')(formulaError), prop('errorLine')(formulaError), prop('errorPosition')(formulaError) + 5), style.errorMarker, 'text');
        }
    

    【讨论】:

    • 请提供简短的文字说明,以便我们自行理解您的答案,而无需反复回答问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多