Set Value for ace editor without selecting the whole editor

前端 未结 6 631
臣服心动
臣服心动 2021-02-06 20:04

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

6条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 20:34

    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.

提交回复
热议问题