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

时间:2015-05-26 01:35:33

标签: javascript ace-editor

我想选择第2行进行复制&粘贴在ACE中。有一种方法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);

1 个答案:

答案 0 :(得分:6)

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

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

以下是一个例子:

editor.selection.moveCursorToPosition({row: 1, column: 0});
editor.selection.selectLine();
相关问题