So you can set value of an ace editor with setValue
but after setting the value, the editor will select the whole value of the editor. How do you disable this? This mean when I set value of ace editor to Hello world
, it won't highlight Hello world
You can use the second parameter to control cursor position after setValue
editor.setValue(str, -1) // moves cursor to the start
editor.setValue(str, 1) // moves cursor to the end
You can even use clearSelection() after you do an setValue();
editor.setValue("Hello World");
editor.clearSelection(); // This will remove the highlight over the text
I'm not sure if editor.setValue() is a remnant from the old days or what, but the proper way to set an editor's content is
editor.session.setValue(text);
or
editor.getSession().setValue(text);
This will NOT select the text, so there's no need to do any of the things mentioned on this page.
editor.setValue() explicitly selects all (and forgets to unselect it); but there's no reason to use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With