Skip to content

Clamp negative rows in translate_row_col_to_index - #2122

Open
Kayvan-Zahiri wants to merge 1 commit into
prompt-toolkit:mainfrom
Kayvan-Zahiri:fix/clamp-negative-document-row-2097
Open

Kayvan-Zahiri wants to merge 1 commit into
prompt-toolkit:mainfrom
Kayvan-Zahiri:fix/clamp-negative-document-row-2097

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown

Fixes #2097.

Document.translate_row_col_to_index documents that a negative row becomes zero. The row was passed straight to the line list, so -1 selected the last line.

Document("one\ntwo\nthree").translate_row_col_to_index(-1, 0) now returns 0, and translate_row_col_to_index(-1, 1) returns 1.

Tests: PYTHONPATH=src python -m pytest tests/test_document.py -q → 13 passed. Before the fix, test_translate_row_col_to_index_clamps_negative_row failed (-1 returned index 8).

Made with Cursor

The method documents that a negative row becomes zero. The row was
used as a list index, so -1 selected the last line.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Document.translate_row_col_to_index does not clamp negative rows to zero

1 participant