Ace Editor API:如何选择第2行?

Lut*_*utz 3 javascript ace-editor

我想在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);
Run Code Online (Sandbox Code Playgroud)

eym*_*men 6

初始化ace后,它会创建一个Selection对象实例,因此您无需重新创建它.访问Selection只是使用editor.selection.

另一个重点是selectLine选择当前行(它不接受任何参数).因此,要移动光标并选择您必须首先使用的行moveCursorToPosition.

这是一个例子:

editor.selection.moveCursorToPosition({row: 1, column: 0});
editor.selection.selectLine();
Run Code Online (Sandbox Code Playgroud)