MCPcopy Index your code
hub / github.com/bpython/bpython / cursor_on_closing_char_pair

Function cursor_on_closing_char_pair

bpython/line.py:285–306  ·  view source on GitHub ↗

Checks if cursor sits on closing character of a pair and whether its pair character is directly behind it

(
    cursor_offset: int, line: str, ch: str | None = None
)

Source from the content-addressed store, hash-verified

283
284
285def cursor_on_closing_char_pair(
286 cursor_offset: int, line: str, ch: str | None = None
287) -> tuple[bool, bool]:
288 """Checks if cursor sits on closing character of a pair
289 and whether its pair character is directly behind it
290 """
291 on_closing_char, pair_close = False, False
292 if line is None:
293 return on_closing_char, pair_close
294 if cursor_offset < len(line):
295 cur_char = line[cursor_offset]
296 if cur_char in CHARACTER_PAIR_MAP.values():
297 on_closing_char = True if ch is None else cur_char == ch
298 if cursor_offset > 0:
299 prev_char = line[cursor_offset - 1]
300 if (
301 on_closing_char
302 and prev_char in CHARACTER_PAIR_MAP
303 and CHARACTER_PAIR_MAP[prev_char] == cur_char
304 ):
305 pair_close = True if ch is None else prev_char == ch
306 return on_closing_char, pair_close

Callers 3

backspaceFunction · 0.85
is_closing_quoteMethod · 0.85
on_tabMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected