Skip to content

Commit

Permalink
Test TextArea terminal cursor position update
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Sep 27, 2023
1 parent 1acdd51 commit 6dae86f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions tests/text_area/test_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ def compose(self) -> ComposeResult:
yield text_area


def test_default_selection():
async def test_default_selection():
"""The cursor starts at (0, 0) in the document."""
text_area = TextArea()
assert text_area.selection == Selection.cursor((0, 0))
app = TextAreaApp()
async with app.run_test():
text_area = app.query_one(TextArea)
assert text_area.selection == Selection.cursor((0, 0))


async def test_cursor_location_get():
Expand Down Expand Up @@ -294,3 +296,23 @@ async def test_select_line(index, content, expected_selection):
text_area.select_line(index)

assert text_area.selection == expected_selection


async def test_cursor_screen_offset_and_terminal_cursor_position_update():
class TextAreaCursorScreenOffset(App):
def compose(self) -> ComposeResult:
yield TextArea("abc\ndef")

app = TextAreaCursorScreenOffset()
async with app.run_test():
text_area = app.query_one(TextArea)

assert app.cursor_position == (3, 0)

text_area.cursor_location = (1, 1)

assert text_area.cursor_screen_offset == (4, 1)

# Also ensure that this update has been reported back to the app
# for the benefit of IME/emoji popups.
assert app.cursor_position == (4, 1)
Empty file.

0 comments on commit 6dae86f

Please sign in to comment.