Skip to content

Commit 4953c3b

Browse files
committed
Test for Input.select_on_focus interaction with AppBlur and AppFocus
1 parent 01befb2 commit 4953c3b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/input/test_select_on_focus.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""The standard path of selecting text on focus is well covered by snapshot tests."""
2+
3+
from textual import events
4+
from textual.app import App, ComposeResult
5+
from textual.widgets import Input
6+
from textual.widgets.input import Selection
7+
8+
9+
class InputApp(App[None]):
10+
"""An app with an input widget."""
11+
12+
def compose(self) -> ComposeResult:
13+
yield Input("Hello, world!")
14+
15+
16+
async def test_focus_from_app_focus_does_not_select():
17+
"""When an Input has focused and the *app* is blurred and then focused (e.g. by pressing
18+
alt+tab or focusing another terminal pane), then the content of the Input should not be
19+
fully selected when `Input.select_on_focus=True`.
20+
"""
21+
async with InputApp().run_test() as pilot:
22+
input_widget = pilot.app.query_one(Input)
23+
input_widget.focus()
24+
input_widget.selection = Selection.cursor(0)
25+
assert input_widget.selection == Selection.cursor(0)
26+
pilot.app.post_message(events.AppBlur())
27+
await pilot.pause()
28+
pilot.app.post_message(events.AppFocus())
29+
await pilot.pause()
30+
assert input_widget.selection == Selection.cursor(0)

0 commit comments

Comments
 (0)