【发布时间】:2013-09-07 23:31:10
【问题描述】:
所以你可以用setValue设置一个ace编辑器的值,但是在设置值之后,编辑器会选择编辑器的整个值。你如何禁用它?这意味着当我将 ace 编辑器的值设置为 Hello world 时,它不会突出显示 Hello world
【问题讨论】:
标签: ace-editor
所以你可以用setValue设置一个ace编辑器的值,但是在设置值之后,编辑器会选择编辑器的整个值。你如何禁用它?这意味着当我将 ace 编辑器的值设置为 Hello world 时,它不会突出显示 Hello world
【问题讨论】:
标签: ace-editor
setValue后可以使用第二个参数控制光标位置
editor.setValue(str, -1) // moves cursor to the start
editor.setValue(str, 1) // moves cursor to the end
【讨论】:
您甚至可以在执行 setValue() 后使用 clearSelection();
editor.setValue("Hello World");
editor.clearSelection(); // This will remove the highlight over the text
【讨论】:
editor.setValue() 作为设置编辑器内容的第一个选项。
这对我有用!
editor.setValue(editor.getValue(), 1);
【讨论】:
我不确定 editor.setValue() 是否是过去的遗留物还是什么,但设置编辑器内容的正确方法是
editor.session.setValue(text);
或
editor.getSession().setValue(text);
这不会选择文本,因此无需执行此页面上提到的任何操作。
editor.setValue() 明确选择所有(并忘记取消选择它);但没有理由使用它。
【讨论】:
editor.setValue() 来设置内容。它还说使用editor.getSession().setValue() 设置一个值并重置撤消历史记录,仅此而已。
我也遇到了同样的问题。
即使您可以将第二个参数设置为 1 或 -1,我认为您也应该检查一下:https://ace.c9.io/api/editor.html#Editor.setValue
Editor.setWrapBehavioursEnabled(Boolean enabled)
在创建编辑器后立即使用它。
这对我来说非常有效。
此方法与a user 分享的方法的区别在于插入符号的位置没有改变,您可以使用Editor.selection.moveTo(row, column) 自己移动它,这样用户在使用例如CTRL时不会遇到奇怪的插入符号位置变化+Z 撤消操作:)
【讨论】:
Editor.setWrapBehavioursEnabled(Boolean enabled)会阻止调用editor.setValue时所有文本被选中吗?
var prevtext = $("#editor").val();
prevtext = prevtext + "<br/>";
$("#editor").val(prevtext).blur();
【讨论】: