Reputation: 223
Does anyone know how can I disable the selection of ace.editor? No word selection by mouse and finger.
I tried to use editor.selection(false);
but that does not work.
Upvotes: 7
Views: 10574
Reputation: 53
You can disable the ace editor using below code:
editor.setReadOnly(true);
Upvotes: 3
Reputation: 101
editor.getSession().selection.on('changeSelection', function (e)
{
editor.getSession().selection.clearSelection();
});
Upvotes: 10
Reputation: 9546
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.
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
There is also this approach:
https://github.com/ajaxorg/ace/issues/266
Upvotes: 4
Reputation: 2192
editor.setValue(str, -1) // moves cursor to the start
editor.setValue(str, 1) // moves cursor to the end
Upvotes: 0