Sublime Forum

Function to return current cursor's position?

#1

Hi,

Is there any function in the Plugin API that returns the current position of the cursor in the current view?

0 Likes

#2

Maybe…

[code]# get selected regions as RegionSet
sels = view.sel()

get 1st cursor as Region

cursor1 = sels[0]

startPos, endPos = cursor1.begin(), cursor1.end()[/code]

1 Like

#3

Thanks guillermooo!

I haven’t tested it yet (currently at work), but I’m wondering why cursor position has begin and end? I thought it only has one position.

0 Likes

#4

Sublime has a powerful multi-selection mode. That means there isn’t just the one selection. Selections are merely buffer regions that happen to be selected. Visually, you might see just the caret at times, but in actuality what you are seeing is an empty region (one starting and ending at the same point within the buffer).

If you can spare the time, read sublimator’s guide (link above).

0 Likes