[英]How to disable in ace editor the selection
Does anyone know how can I disable the selection of ace.editor? 有谁知道如何禁用ace.editor的选择? No word selection by mouse and finger. 没有用鼠标和手指选择单词。
I tried to use editor.selection(false);
我试着使用editor.selection(false);
but that does not work. 但这不起作用。
editor.getSession().selection.on('changeSelection', function (e)
{
editor.getSession().selection.clearSelection();
});
You can effectively prevent selection by setting the editor to read only then overriding the selection style in the theme: 您可以通过将编辑器设置为只读然后覆盖主题中的选择样式来有效地阻止选择:
.noselection .ace_marker-layer .ace_selection {
background: transparent;
}
.noselection .ace_cursor {
color: transparent;
}
Then just add the noselection
class to your ace container div. 然后只需将noselection
类添加到ace容器div中。
This won't actually prevent the user selecting anything, but there will be no visual indication that its happening; 这实际上不会阻止用户选择任何东西,但是没有视觉指示它正在发生; which for all intents and purposes is pretty much the same thing. 对于所有意图和目的来说几乎都是一样的。
Lots more detail here: 这里有更多细节:
https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode
There is also this approach: 还有这种方法:
https://github.com/ajaxorg/ace/issues/266 https://github.com/ajaxorg/ace/issues/266
editor.setValue(str, -1) // moves cursor to the start editor.setValue(str,-1)//将光标移动到开头
editor.setValue(str, 1) // moves cursor to the end editor.setValue(str,1)//将光标移动到结尾
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.