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
- 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;
- 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
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
Steps to reproduce
\r, for example:Actual behavior
sqlit crashes in
AutocompleteMixin._location_to_offset:The editor reports a cursor location such as
(8, 21), whiletext.split("\n")returns only one line because the text contains\rseparators.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:
\n): works\r\n): works\r): reproduces theIndexError