Skip to content

Autocomplete crashes on CR-only line endings #292

Description

@bolexyro

Description

Autocomplete crashes when the query text contains carriage-return-only (\r) line endings. This can occur after pasting multiline SQL on Windows and then editing the query, which triggers autocomplete.

Environment

  • sqlit-tui: 1.5.2
  • OS: Windows

Steps to reproduce

  1. Paste multiline text whose lines are separated by \r, for example:
SELECT
    a.attname AS column_name,
    format_type(a.atttypid, a.atttypmod) AS data_type
FROM
    pg_catalog.pg_attribute a
JOIN
    pg_catalog.pg_class c ON a.attrelid = c.oid
WHERE
    c.relname = 'users'
    AND a.attnum > 0
    AND NOT a.attisdropped;
  1. Edit the text (for example, press Backspace) so autocomplete runs.

Actual behavior

sqlit crashes in AutocompleteMixin._location_to_offset:

IndexError: list index out of range
  File "sqlit/domains/query/ui/mixins/autocomplete.py", line 92
    offset = sum(len(lines[i]) + 1 for i in range(row))

The editor reports a cursor location such as (8, 21), while text.split("\n") returns only one line because the text contains \r separators.

Expected behavior

Autocomplete should handle LF, CRLF, and CR-only line endings without crashing, and cursor locations should round-trip correctly.

Reproduction result

Tested directly against 1.5.2:

  • LF (\n): works
  • CRLF (\r\n): works
  • CR-only (\r): reproduces the IndexError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions