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
)
| 283 | |
| 284 | |
| 285 | def 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 |
no outgoing calls
no test coverage detected