Question

I'm trying to get the line and col from a region. So the line and col from the beginning and the end. But I didn't find any function for this in the Sublime Text API.

Does anyone know how to do this?

Thanks in advance.

Was it helpful?

Solution

The API to call is view.rowcol.


To use it on a region in a selection, assume you have a region r.

You can use

startrow, startcol = view.rowcol(r.a)
endrow, endcol = view.rowcol(r.b)

{
    'start': {'line': startrow, 'col': startcol},
    'end': {'line': endrow, 'col': endcol}
}

Note that "start" and "end" have a variety of meanings with regards to selections. You might for instance want to replace r.a, r.b with r.begin(), r.end().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top