Home Download Buy Blog Forum Support

caret position

caret position

Postby sapphirehamster on Mon Jul 23, 2012 9:09 am

Sublime seems to remember the column of the cursor as you move up and down lines. If you reach a line that is shorter than the previous line, the cursor will be positioned at the end of the line. Pressing up or down will return to the previous column (not the column equivalent to the end of that short line). Various actions like typing resets this column memory. I'm not even sure what to call this behavior, so it's been hard searching for any information about it.

This memory seems to be attached to the Region object, in the xpos() or meta() value. However, this is undocumented. Will this value be documented at some point? On my system, this value appears to be the remembered column number times 7, which is the em_width(). Is it safe to assume all characters are this width?

Would love to have access to this for a plugin I'm writing, but I'm not sure if it's safe.
sapphirehamster
 
Posts: 83
Joined: Sun Jul 01, 2012 11:19 pm

Re: caret position

Postby jps on Tue Jul 24, 2012 11:22 am

It's safe to use, you won't break anything by modifying it apart from the desired x position of the caret. The value is in layout coordinates, and it's not safe to assume that all characters are the same width: tabs are always a different width, or the user may be using a variable width font. You can use text_to_layout() to get an appropriate value though.
jps
Site Admin
 
Posts: 3062
Joined: Wed Mar 19, 2008 12:33 pm

Re: caret position

Postby sapphirehamster on Tue Jul 24, 2012 11:05 pm

Thanks!!
sapphirehamster
 
Posts: 83
Joined: Sun Jul 01, 2012 11:19 pm


Return to Plugin Development

Who is online

Users browsing this forum: Alexa [Bot] and 8 guests