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-in
(text:str, line:int, column:int)
| 813 | |
| 814 | |
| 815 | def cursor_to_position(text:str, line:int, column:int)->int: |
| 816 | """ |
| 817 | |
| 818 | Convert the (line,column) position of the cursor in text to an offset in a |
| 819 | string. |
| 820 | |
| 821 | Parameters |
| 822 | ---------- |
| 823 | |
| 824 | text : str |
| 825 | The text in which to calculate the cursor offset |
| 826 | line : int |
| 827 | Line of the cursor; 0-indexed |
| 828 | column : int |
| 829 | Column of the cursor 0-indexed |
| 830 | |
| 831 | Return |
| 832 | ------ |
| 833 | Position of the cursor in ``text``, 0-indexed. |
| 834 | |
| 835 | See Also |
| 836 | -------- |
| 837 | position_to_cursor: reciprocal of this function |
| 838 | |
| 839 | """ |
| 840 | lines = text.split('\n') |
| 841 | assert line <= len(lines), '{} <= {}'.format(str(line), str(len(lines))) |
| 842 | |
| 843 | return sum(len(l) + 1 for l in lines[:line]) + column |
| 844 | |
| 845 | def position_to_cursor(text:str, offset:int)->Tuple[int, int]: |
| 846 | """ |
no test coverage detected