Convert the (line,column) position of the cursor in text to an offset in a string. Parameters ---------- text : str The text in which to calculate the cursor offset line : int Line of the cursor; 0-indexed column : int Column of the cursor 0-inde
(text:str, line:int, column:int)
| 1646 | |
| 1647 | |
| 1648 | def cursor_to_position(text:str, line:int, column:int)->int: |
| 1649 | """ |
| 1650 | Convert the (line,column) position of the cursor in text to an offset in a |
| 1651 | string. |
| 1652 | |
| 1653 | Parameters |
| 1654 | ---------- |
| 1655 | text : str |
| 1656 | The text in which to calculate the cursor offset |
| 1657 | line : int |
| 1658 | Line of the cursor; 0-indexed |
| 1659 | column : int |
| 1660 | Column of the cursor 0-indexed |
| 1661 | |
| 1662 | Returns |
| 1663 | ------- |
| 1664 | Position of the cursor in ``text``, 0-indexed. |
| 1665 | |
| 1666 | See Also |
| 1667 | -------- |
| 1668 | position_to_cursor : reciprocal of this function |
| 1669 | |
| 1670 | """ |
| 1671 | lines = text.split('\n') |
| 1672 | assert line <= len(lines), '{} <= {}'.format(str(line), str(len(lines))) |
| 1673 | |
| 1674 | return sum(len(line) + 1 for line in lines[:line]) + column |
| 1675 | |
| 1676 | |
| 1677 | def position_to_cursor(text: str, offset: int) -> tuple[int, int]: |
no test coverage detected
searching dependent graphs…