javascript - Ace 编辑器 API : How to select line 2?

标签 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);

最佳答案

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/

相关文章:

javascript - 为什么 JavaScript 提交重新加载页面并通过按钮提交进行客户端页面验证

javascript - 如何在javascript中获取浏览器滚动条的高度

javascript - 向 Quill 添加自定义按钮操作

javascript - 如何找到树结构中的所有唯一路径

javascript - 如何将 form_for 与非输入元素一起使用?

javascript - 可以有条件地加载 Firebug Lite 吗?

php - Ace 编辑器未处理 '&'

ace-editor - 如何突出显示多项选择?

token - 获取 ace 编辑器的 token 字符串

codemirror - Elm 有可嵌入的代码编辑器吗?