From 46dc3ec272462569e3098c09c741f3d2b82e9240 Mon Sep 17 00:00:00 2001 From: Jakob Zahn Date: Thu, 9 May 2024 01:38:19 +0200 Subject: [PATCH] Add tests for cursor row offset --- tests/text_area/test_edit_via_api.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/text_area/test_edit_via_api.py b/tests/text_area/test_edit_via_api.py index e217bfa210..e732680f0f 100644 --- a/tests/text_area/test_edit_via_api.py +++ b/tests/text_area/test_edit_via_api.py @@ -106,6 +106,27 @@ async def test_insert_character_near_cursor_maintain_selection_offset( assert text_area.selection == Selection.cursor(cursor_destination) +@pytest.mark.parametrize( + "cursor_location,insert_location,cursor_destination", + [ + ((1, 0), (0, 0), (2, 0)), # API insert before cursor row + ((0, 0), (0, 0), (1, 0)), # API insert right at cursor row + ((0, 0), (1, 0), (0, 0)), # API insert after cursor row + ], +) +async def test_insert_newline_around_cursor_maintain_selection_offset( + cursor_location, + insert_location, + cursor_destination +): + app = TextAreaApp() + async with app.run_test(): + text_area = app.query_one(TextArea) + text_area.move_cursor(cursor_location) + text_area.insert("X\n", location=insert_location) + assert text_area.selection == Selection.cursor(cursor_destination) + + async def test_insert_newlines_start(): app = TextAreaApp() async with app.run_test():