Skip to content

Handle CR line endings in the query editor - #293

Draft
bolexyro wants to merge 2 commits into
Maxteabag:mainfrom
bolexyro:agent/fix-autocomplete-cr-line-endings
Draft

Handle CR line endings in the query editor#293
bolexyro wants to merge 2 commits into
Maxteabag:mainfrom
bolexyro:agent/fix-autocomplete-cr-line-endings

Conversation

@bolexyro

@bolexyro bolexyro commented Aug 11, 2026

Copy link
Copy Markdown

Summary

  • normalize CRLF and CR-only clipboard text to LF before inserting it into the query editor
  • preserve newline widths when converting autocomplete cursor locations to string offsets
  • support LF, CRLF, and CR-only text in both cursor-conversion directions
  • add regression coverage for pasted line endings, cursor round trips, trailing line endings, and empty text

Root cause

The paste helper split clipboard content only on \n. CR-only clipboard content was therefore inserted unchanged even though Textual displayed it as multiple rows. That left the SQL highlighter and line-oriented editing operations with malformed input. Autocomplete also split only on \n, so Textual could report a multi-row cursor location while sqlit saw a single line, causing _location_to_offset to index past the line list.

User impact

Pasted multiline SQL now uses the editor's expected LF representation, so syntax highlighting remains correct. Autocomplete also no longer crashes if CR or CRLF text reaches its cursor conversion helpers, and the cursor remains correctly positioned after applying a completion.

Fixes #292.

Validation

  • pytest tests/unit/test_autocomplete_cursor_positions.py tests/unit/test_query_paste.py --timeout=60: 10 passed
  • pytest tests/unit -q --timeout=60: 1122 passed, 2 skipped
  • ruff check on changed source and test files: passed
  • mypy on changed source files: passed

Validation ran in a Python 3.12 container.

@bolexyro bolexyro changed the title Fix autocomplete cursor offsets for CR line endings Handle CR line endings in the query editor Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autocomplete crashes on CR-only line endings

1 participant