Skip to content

Handle CR line endings in the query editor - #293

Merged
Maxteabag merged 3 commits into
Maxteabag:mainfrom
bolexyro:agent/fix-autocomplete-cr-line-endings
Aug 23, 2026
Merged

Handle CR line endings in the query editor#293
Maxteabag merged 3 commits into
Maxteabag:mainfrom
bolexyro:agent/fix-autocomplete-cr-line-endings

Conversation

@bolexyro

@bolexyro bolexyro commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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
@bolexyro
bolexyro marked this pull request as ready for review August 16, 2026 18:40
@Maxteabag

Copy link
Copy Markdown
Owner

Thanks for the contribution and for tracking this down. I added one small follow-up regression on top of your branch so CR-only text is also treated as a boundary when a completion is actually applied; otherwise accepting a suggestion could scan into the preceding line. I also kept non-ASCII identifier characters behaving as before.

The focused line-ending and autocomplete suite now passes all 12 tests, and the final structured review is clean. Thanks again!

@Maxteabag
Maxteabag merged commit a72860c into Maxteabag:main Aug 23, 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

2 participants