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.
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? :/
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.
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? :/
Share Improve this question edited Oct 24, 2017 at 17:55 Stefan Falk asked Oct 24, 2015 at 23:14 Stefan FalkStefan Falk 25.6k61 gold badges218 silver badges412 bronze badges 2- 1 Have you finished that project? Sound like an interesting one. – Adrian Moisa Commented Oct 24, 2017 at 17:47
- 1 @AdrianMoisa Well, yes I finished it but I don't think I'd find the project - it was just for an exercise on the university. However, it's rather simple to get something like that running assuming you know how to translate the code to bytecode and have some basic knowledge about either assembly or how a cpu works. – Stefan Falk Commented Oct 24, 2017 at 17:51
3 Answers
Reset to default 6add 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"
);
}
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');
}
set a variable marker
to receive the return value, just like this:
marker=editor.session.addMarker(range, "myMarker", "fullLine");
and then remove this marker, like this:
editor.session.removeMarker(marker);