Home Download Buy Blog Forum Support

how to get the current cursor location/point

how to get the current cursor location/point

Postby oLinkSW0001 on Wed Jun 16, 2010 11:17 pm

Hello;

I'm trying to paste some text into wherever the cursor happens to be, so I need to figure out how to extract the current location of the cursor.

My hunch is that I need to use view.rowcol(), but I can't get it working, so I'm wondering if someone can suggest a solution to getting the current location/point of the cursor such that view.insert() could be used to paste something right on it.

Regards;
oLinkSW0001
 
Posts: 5
Joined: Thu Jun 03, 2010 6:11 am

Re: how to get the current cursor location/point

Postby edanm on Thu Jun 17, 2010 6:11 am

Firstly, if you don't know about it, check out the api reference: http://www.sublimetext.com/docs/api-reference.
To get the cursor, you call
Code: Select all
for region in view.sel():


Since Sublime Text works with multiple cursors, view.sel() will give you back a RegionSet (a list of regions), each region representing one "selection" (this can either be just a cursor, in which case the reigon's two points are at the same place, or an actual selection if you've got selected text).

So let's say I wanted to insert text into all the places where my cursor is, I'd do:
Code: Select all
for region in view.sel(): # Loop over all the cursors
            view.insert(region.begin(), "string to insert") # Insert into the view at the start of each selection.
edanm
 
Posts: 131
Joined: Thu Mar 04, 2010 11:05 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 13 guests