我想在 ACE 中选择第 2 行进行复制和粘贴。有一种方法 selectLine()
,记录在此处:http://ace.c9.io/#nav=api&api=selection但我不明白如何使用它。不幸的是,它在 stackoverflow.com 上也找不到关于选择的内容,只有关于突出显示的内容,这是不一样的。
// ACE Editor Setup
var editor = ace.edit("editor");
editor.setTheme("ace/theme/crimson_editor");
editor.getSession().setMode("ace/mode/html");
editor.setValue("textline1\n textline2\n textline3");
var select = new Selection(editor.getSession()); // Uncaught TypeError: Illegal constructor
select.selectLine(2);
最佳答案
ace 初始化后,它会创建一个Selection
对象实例,因此您无需重新创建它。要访问 Selection
,只需使用 editor.selection
。
另一个重点是selectLine
选择当前行(它不接受任何参数)。因此,要移动光标并选择您必须首先使用 moveCursorToPosition
函数的行。
这是一个例子:
editor.selection.moveCursorToPosition({row: 1, column: 0});
editor.selection.selectLine();
关于javascript - Ace 编辑器 API : How to select line 2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30448117/