admin管理员组文章数量:1023099
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);
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);
本文标签: javascriptAce Editor Can39t get rid of MarkerStack Overflow
版权声明:本文标题:javascript - Ace Editor: Can't get rid of Marker - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745561553a2156189.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论