我试图根据用户输入的内容,在ace编辑器中动态地将文本方向更新为"LTR“或"RTL”。
我正在监听ace编辑器上的change事件,并在通过ace.js之后编写以下代码
scope.editor.session.$bidiHandler.setTextDir(_isNewValueRTL);
scope.editor.session.$bidiHandler.updateBidiMap();_isNewValueRTL是一个布尔值。我不认为这能行得通。
任何帮助我们都将不胜感激。
发布于 2018-11-13 21:23:58
Ace目前没有setTextDir方法,它支持基于行的方向https://github.com/ajaxorg/ace/pull/3400,其工作方式是将'RIGHT-TO-LEFT EMBEDDING' (U+202B)添加到行中
要使用包含的ext-rtl.js
editor.setOption("rtlText", true)然后更改游标行调用的方向
<script src=https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.1/ace.js ></script>
<script src=https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.1/ext-rtl.js ></script>
<script>
debugger
editor = ace.edit(null, {
value: " left\n\u202B right\n\n try press ctrl-alt-shift-r or ctrl-alt-shift-l ",
rtlText: true,
})
document.body.appendChild(editor.container)
editor.container.style.cssText = "height: 150px; width: 400px; outline: solid"
</script>
editor.session.$bidiHandler.setRtlDirection(editor, true)如果您需要一些其他功能,则向ace https://github.com/ajaxorg/ace/issues/new打开一个功能请求
发布于 2018-11-14 01:36:46
尝试将此CSS添加到您的ace_line类
.ace_line {
direction: ltr;
unicode-bidi: bidi-override;
}这应该会改变文本的方向
https://stackoverflow.com/questions/53278788
复制相似问题