Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ace Editor: Can't get rid of Marker

I am writing a simple widget that simulates a simple 8-bit CPU. For that I am abusing the Ace Editor, as you can see at the center of the image, as my "RAM"-view.

enter image description here

I want to highlight the line that corresponds to the value of the program counter and I am using addMarker() to do so.

However, I can't seem to get rid of that marker once I have set it. _marker is a private member that holds the value of the last marker set. But for some reason removeMarker(_marker) has no effect:

/**
 *
 */
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"
    );
}

What am I doing wrong here? :/

like image 366
Stefan Falk Avatar asked Oct 16 '25 14:10

Stefan Falk


1 Answers

add marker returns an id, and removeMarker requires that id, so you can do something like

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"
    );
}
like image 58
a user Avatar answered Oct 19 '25 07:10

a user



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!