我正在为我的网站使用ACE编辑器。我需要在编辑器中选择/突出显示某些行。但是当代码很大时,ACE编辑器会显示一些错误,比如,当它向下滚动行号更改时,突出显示的行号与我想要突出显示的行号不同。我已经搜索并找到了这个Problem.,但实际上我无法理解它。谁能给出一些在ACE编辑器中突出显示一行的例子?下面是我当前的代码:
var aceLines = document.getElementsByClassName("ace_line");
var gutters = document.getElementsByClassName("ace_gutter-cell");
var gutLineNo = parseInt(gutters[0].innerHTML)-1;
if(count1 != 0){
aceLines[arNum[count]-gutLineNo].style.backgroundColor = "green";
aceLines[arNum[count1]-gutLineNo].style.backgroundColor = "black";
}else{
aceLines[arNum[count]-gutLineNo].style.backgroundColor = "green";
}
发布于 2014-12-18 13:57:15
不要试图直接修改编辑器dom。Ace只为可见线创建dom节点,您需要像How can I highlight multiple lines with Ace?中描述的那样使用setMarker。
首先创建一个设置背景的css类
.myMarker {
position:absolute;
background:rgba(100,200,100,0.5);
z-index:20
}
然后添加一个标记
var Range = ace.require('ace/range').Range;
editor.session.addMarker(new Range(from, 0, to, 1), "myMarker", "fullLine");
这里的from
和to
是要突出显示的行数
https://stackoverflow.com/questions/27531860
复制