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.

有帮助吗?

解决方案

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().

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top