Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top