Reputation: 93
I'm using Ace Editor. In Javascript, (not jQuery), how would I return the current cursor row and column position?
Upvotes: 9
Views: 8679
Reputation: 986
This is the function that will get you the object.
getCursor() //The name of this function it may have been changed - this is a current one as of September 2016
It returns a Position Object that consists of two members:
row
column
Ways to use it are:
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
Let's say you want want to pass this object as a parameter to some other function such as:
InstanceOfYourEditor.selection.insert() //accepts Position Object and a text to insert
then you can just pass the Object as is
InstanceOfYourEditor.selection.insert(oPositionObject, "Just Want To Provide A More Detailed Answer So My Fellows Can Better Visualize It All");
This answer was more of "fishing for you" - but I encourage you to learn how to fish in general and specifically with Ace Editor object by referring to the Ace Editor API that contains all the information about the object.
ACE EDITOR API - Selection Section
Upvotes: 2
Reputation: 24159
editor.getCursorPosition()
returns an object with row and column properties
Upvotes: 9