Set Value for ace editor without selecting the whole editor

前端 未结 6 628
臣服心动
臣服心动 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:49

    I've been having your same issue.

    Even though you can set the second parameter to either 1 or -1, I think you should also check this: https://ace.c9.io/api/editor.html#Editor.setValue

    Editor.setWrapBehavioursEnabled(Boolean enabled)
    

    Use this right after creating the editor.

    This works very well for me. The difference between this method and the one shared by a user is that the caret's position is not changed, you can move it yourself using Editor.selection.moveTo(row, column), this way the user won't experience weird caret position changes when using, say, CTRL+Z to undo an action :)

提交回复
热议问题