为ace编辑器设置值而不选择整个编辑器

Pix*_*ded 84 ace-editor

因此,您可以设置ace编辑器setValue的值,但在设置值后,编辑器将选择编辑器的整个值.你怎么禁用这个?这意味着当我将ace编辑器的值设置为时Hello world,它不会突出显示Hello world

a u*_*ser 150

您可以使用第二个参数来控制setValue之后的光标位置

editor.setValue(str, -1) // moves cursor to the start
editor.setValue(str, 1) // moves cursor to the end
Run Code Online (Sandbox Code Playgroud)


Dan*_*ial 13

我不确定 editor.setValue() 是否是旧时代的残余或什么,但设置编辑器内容的正确方法是

editor.session.setValue(text);
Run Code Online (Sandbox Code Playgroud)

或者

editor.getSession().setValue(text);
Run Code Online (Sandbox Code Playgroud)

这不会选择文本,因此无需执行此页面上提到的任何操作。

editor.setValue() 显式选择全部(并且忘记取消选择它);但没有理由使用它。


Har*_*pps 12

在执行setValue()之后,您甚至可以使用clearSelection();

editor.setValue("Hello World");
editor.clearSelection(); // This will remove the highlight over the text
Run Code Online (Sandbox Code Playgroud)


cir*_*try 9

这适合我!

editor.setValue(editor.getValue(), 1);
Run Code Online (Sandbox Code Playgroud)