Ace Editor 获取当前光标行和列

Ace Editor Get Current Cursor Row and Column

我正在使用 Ace 编辑器。在Javascript,(不是jQuery),我如何return当前光标行和列位置?

editor.getCursorPosition() returns 具有行和列属性的对象

这是为您获取对象的函数。

getCursor() //The name of this function it may have been changed - this is a current one as of September 2016

它returns一个由两个成员组成的位置对象:

row
column

使用方法有:

var iRowPosition;
var iColumnPosition;

var oPositionObject;

oPositionObject = InstanceOfYourEditor.selection.getCursor(); // to get the Position Object
iRowPosition = InstanceOfYourEditor.selection.getCursor().row; // to get the Row Position 
iColumnPosition = InstanceOfYourEditor.selection.getCursor().column; // to get the Column Position 

假设您想将此对象作为参数传递给其他函数,例如:

InstanceOfYourEditor.selection.insert() //accepts Position Object and a text to insert

然后你可以按原样传递对象

InstanceOfYourEditor.selection.insert(oPositionObject, "Just Want To Provide A More Detailed Answer So My Fellows Can Better Visualize It All");

这个答案更多的是 "fishing for you" - 但我鼓励您通过参考包含所有信息的 Ace 编辑器 API 学习如何使用 Ace 编辑器对象钓鱼物体。

ACE EDITOR API - Selection Section