如何在ace编辑器中禁用选择

use*_*577 3 javascript ace-editor

有谁知道如何禁用ace.editor的选择?没有用鼠标和手指选择单词.

我试着用 editor.selection(false);

但这不起作用.

小智 8

editor.getSession().selection.on('changeSelection', function (e)
{
    editor.getSession().selection.clearSelection();
});
Run Code Online (Sandbox Code Playgroud)


Kon*_*ong 4

您可以通过将编辑器设置为只读然后覆盖主题中的选择样式来有效地防止选择:

.noselection .ace_marker-layer .ace_selection {
   background: transparent;
}

.noselection .ace_cursor {
   color: transparent;
}
Run Code Online (Sandbox Code Playgroud)

然后只需将该noselection类添加到您的 ace 容器 div 中即可。

这实际上不会阻止用户选择任何内容,但不会有任何视觉指示表明它正在发生;就所有意图和目的而言,这几乎是同一件事。

这里有更多详细信息:

https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode

还有这样的做法:

https://github.com/ajaxorg/ace/issues/266