문제

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