Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Value for ace editor without selecting the whole editor

Tags:

ace-editor

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

like image 415
Pixeladed Avatar asked Sep 04 '13 12:09

Pixeladed


3 Answers

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
like image 198
a user Avatar answered Nov 05 '22 16:11

a user


You can even use clearSelection() after you do an setValue();

editor.setValue("Hello World");
editor.clearSelection(); // This will remove the highlight over the text
like image 17
Harsha pps Avatar answered Nov 05 '22 14:11

Harsha pps


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.

like image 11
Danial Avatar answered Nov 05 '22 16:11

Danial