当我用鼠标移动它时,我想在ace编辑器中强调一部分代码,甚至更多,将鼠标光标显示为指针。 我试过这样做:
editSession.addMarker(new Range(loc.start.line - 1, loc.start.column, loc.end.line - 1, loc.end.column), "ace_underline", "text")
这不起作用。令我感到困惑的是,如果我用ace_underline
或addMarker
替换ace_highlight-marker
(ace_selection
函数的第二个参数),它的作用就是我想要的范围得到着色。
我还尝试创建自己的css类,如下所示:
.myCustomMouseOverHighlight {
text-decoration: underline;
cursor: pointer !important;
}
然后用myCustomMouseOverHighlight
替换第二个参数,但是再次无效。
任何指针都将受到高度赞赏。
拉杜
答案 0 :(得分:3)
它不起作用,因为addMarker在文本后面添加了一个div。尝试
.myCustomMouseOverHighlight {
border-bottom: 1px solid red;
position: absolute;
cursor: pointer !important;
pointer-events: auto;
}
<script src="https://ajaxorg.github.io/ace-builds/src/ace.js"></script>
<style>
.myCustomMouseOverHighlight {
border-bottom: 1px solid red;
position: absolute;
cursor: pointer !important;
pointer-events: auto;
}
</style>
<script>
var Range = ace.Range;
var editor = ace.edit(null, {value: "Hello World"});
editor.container.style.height = "100px";
document.body.appendChild(editor.container);
editor.session.addMarker(new Range(0, 1, 0, 5), "myCustomMouseOverHighlight", "text")
</script>