Sublime Forum

Set cursor position

#1

It would be very helpful if view.show (view, textcol (row, col)) would place the cursor at (row, col)

0 Likes

View.replace & view.erase bug?
#2

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)

0 Likes

#3

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.

0 Likes

#4

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.

0 Likes

#5

I realize it’s time to reset my mental model about text editors throwing away the line oriented stuff and thinking in regions.

0 Likes