diff --git a/CHANGELOG.md b/CHANGELOG.md index e8ae366c14..5a062ac6c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed `TextArea` cursor display on wrapped lines https://github.com/Textualize/textual/pull/6196 - Fixed `remove_children` not refreshing layout https://github.com/Textualize/textual/pull/6206 - Fixed flicker with :hover pseudo class https://github.com/Textualize/textual/pull/6214 +- Fixed scrollbar not updating after textarea paste https://github.com/Textualize/textual/pull/6219 ### Added diff --git a/src/textual/widgets/_text_area.py b/src/textual/widgets/_text_area.py index 5ef4dc9066..262da2c52a 100644 --- a/src/textual/widgets/_text_area.py +++ b/src/textual/widgets/_text_area.py @@ -1158,6 +1158,7 @@ def _refresh_size(self) -> None: # +1 width to make space for the cursor resting at the end of the line width, height = self.document.get_size(self.indent_width) self.virtual_size = Size(width + self.gutter_width + 1, height) + self._refresh_scrollbars() @property def _draw_cursor(self) -> bool: @@ -1561,11 +1562,11 @@ def edit(self, edit: Edit) -> EditResult: result.end_location, ) - self._refresh_size() edit.after(self) self._build_highlight_map() self.post_message(self.Changed(self)) self.update_suggestion() + self._refresh_size() return result def undo(self) -> None: diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_text_area_paste.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_text_area_paste.svg new file mode 100644 index 0000000000..040da08f58 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_text_area_paste.svg @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TextAreaApp + + + + + + + + + + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                     ▇▇ +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will                                                      +Where there is a Will +▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index bcb3cb93fb..4eba817cdd 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -4781,3 +4781,22 @@ def compose_things() -> ComposeResult: await self.screen.mount_compose(compose_things()) assert snap_compare(ComposeApp()) + + +def test_text_area_paste(snap_compare) -> None: + """Regression test for https://github.com/Textualize/textual/issues/4852 + + You should see a TextArea where the scrollbar and cursor at at the bottom + of the document. + """ + + class TextAreaApp(App): + def compose(self) -> ComposeResult: + yield TextArea() + + async def run_before(pilot: Pilot) -> None: + await pilot.pause() + pilot.app._clipboard = "\n".join(["Where there is a Will"] * 100) + await pilot.press("ctrl+v") + + assert snap_compare(TextAreaApp(), run_before=run_before)