MCPcopy Index your code
hub / github.com/ipython/ipython / cursor_to_position

Function cursor_to_position

IPython/core/completer.py:1648–1674  ·  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-inde

(text:str, line:int, column:int)

Source from the content-addressed store, hash-verified

1646
1647
1648def 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
1677def position_to_cursor(text: str, offset: int) -> tuple[int, int]:

Callers 2

get_completionsMethod · 0.90
_jedi_matchesMethod · 0.85

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…