MCPcopy Create free account
hub / github.com/ipython/ipython / cursor_to_position

Function cursor_to_position

IPython/core/completer.py:815–843  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

813
814
815def 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
845def position_to_cursor(text:str, offset:int)->Tuple[int, int]:
846 """

Callers 2

get_completionsMethod · 0.90
_jedi_matchesMethod · 0.85

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected