Sublime Forum

Caret position

#1

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.

1 Like

How: Cursor beyond end-of-line?
ST3 API changes and Will Bond's plugin tutorial
#2

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.

1 Like

#3

Thanks!!

0 Likes