Home Download Buy Blog Forum Support

set cursor position

set cursor position

Postby tgkeul on Mon May 25, 2009 9:50 pm

It would be very helpful if view.show (view, textcol (row, col)) would place the cursor at (row, col)
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm

Re: set cursor position

Postby tgkeul on Fri May 29, 2009 4:27 pm

I'm looking for a possibility to position the cursor at a textposition.

I have a onPreSave() method which strips trailing spaces. After this operation the cursor is at the end of file. I want it back to the textposition before onPreSave() starts. Simply I need a view.moveTo (textposition)
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm

Re: set cursor position

Postby tgkeul on Sat May 30, 2009 7:00 pm

Thank you for this solution.
One need to know a lot how sublime works to get this non obvious solution.

As a friend of the "keep it simple" strategy I would prefer a straight forward solution like "push(row, col); rstrip(all_lines); moveto(pop(row,col))"
But I'm very happy with it, thank you again.
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm

Re: set cursor position

Postby jps on Sun May 31, 2009 12:33 am

In general, if you want to modify the buffer while preserving selections, you need to do it via calls to view.erase(), view.insert(), or view.replace(). These functions preserve the selection, and other state that's relative to positions in the document, such as bookmarks, in-progress snippets, and (in the future) other plugin state.

The next version of Sublime Text will have a findAll() method in the API, so removing all whitespace using the above functions won't be so roundabout.
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

Re: set cursor position

Postby tgkeul on Sun May 31, 2009 9:46 am

I realize it's time to reset my mental model about text editors throwing away the line oriented stuff and thinking in regions.
tgkeul
 
Posts: 140
Joined: Tue Dec 02, 2008 9:35 pm


Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 4 guests