Test selecting text after a widget is removed. Regression test for https://github.com/Textualize/textual/issues/6452
()
| 732 | |
| 733 | |
| 734 | async def test_select_remove(): |
| 735 | """Test selecting text after a widget is removed. |
| 736 | |
| 737 | Regression test for https://github.com/Textualize/textual/issues/6452 |
| 738 | |
| 739 | """ |
| 740 | |
| 741 | top_text = "Hello, World " * 20 |
| 742 | vanish_text = "This will vanish " * 10 |
| 743 | |
| 744 | class SelApp(App): |
| 745 | |
| 746 | BINDINGS = [("space", "vanish")] |
| 747 | |
| 748 | def compose(self) -> ComposeResult: |
| 749 | yield Static(top_text) |
| 750 | yield Static(vanish_text, id="vanish") |
| 751 | |
| 752 | def action_vanish(self) -> None: |
| 753 | self.query_one("#vanish").remove() |
| 754 | |
| 755 | app = SelApp() |
| 756 | # Simulate mouse down, move to second widget, remove second widget, move mouse, mouse up |
| 757 | # Prior to the fix this would result in an error as the second widget was no longer attached |
| 758 | # Post fix, there should be no error, and the selected text should be from the first widget. |
| 759 | async with app.run_test() as pilot: |
| 760 | await pilot.mouse_down(offset=(5, 2)) |
| 761 | await pilot.hover(offset=(20, 5)) |
| 762 | await app.query_one("#vanish").remove() |
| 763 | await pilot.hover(offset=(25, 6)) |
| 764 | await pilot.mouse_up(offset=(30, 5)) |
| 765 | selected_text = app.screen.get_selected_text() |
| 766 | expected = ", World Hello, World Hello, World Hello, World Hello, World Hello, World Hello, World Hello, World " |
| 767 | print(repr(selected_text)) |
| 768 | assert selected_text == expected |
nothing calls this directly
no test coverage detected
searching dependent graphs…