diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fa7994348..497ae2bc23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed `Tab` enable/disable messages leaking into `TabbedContent` https://github.com/Textualize/textual/issues/4233 - Fixed a style leak from `TabbedContent` https://github.com/Textualize/textual/issues/4232 - Fixed active hidden scrollbars not releasing the mouse https://github.com/Textualize/textual/issues/4274 +- Fixed the mouse not being released when hiding a `TextArea` while mouse selection is happening https://github.com/Textualize/textual/issues/4292 ### Changed diff --git a/src/textual/widgets/_text_area.py b/src/textual/widgets/_text_area.py index dc2ea49d44..c4e9a8bbfd 100644 --- a/src/textual/widgets/_text_area.py +++ b/src/textual/widgets/_text_area.py @@ -1498,13 +1498,21 @@ async def _on_mouse_move(self, event: events.MouseMove) -> None: selection_start, _ = self.selection self.selection = Selection(selection_start, target) - async def _on_mouse_up(self, event: events.MouseUp) -> None: + def _end_mouse_selection(self) -> None: """Finalize the selection that has been made using the mouse.""" self._selecting = False self.release_mouse() self.record_cursor_width() self._restart_blink() + async def _on_mouse_up(self, event: events.MouseUp) -> None: + """Finalize the selection that has been made using the mouse.""" + self._end_mouse_selection() + + async def _on_hide(self, event: events.Hide) -> None: + """Finalize the selection that has been made using the mouse when thew widget is hidden.""" + self._end_mouse_selection() + async def _on_paste(self, event: events.Paste) -> None: """When a paste occurs, insert the text from the paste event into the document.""" if self.read_only: