Skip to content

Commit 6b8790e

Browse files
authored
Merge pull request #4295 from davep/ungreedyify-textarea
Fix `TextArea` holding on to focus when hidden while doing a mouse selection
2 parents 8c0077a + 96ee503 commit 6b8790e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3333
- Fixed `Tab` enable/disable messages leaking into `TabbedContent` https://github.com/Textualize/textual/issues/4233
3434
- Fixed a style leak from `TabbedContent` https://github.com/Textualize/textual/issues/4232
3535
- Fixed active hidden scrollbars not releasing the mouse https://github.com/Textualize/textual/issues/4274
36+
- Fixed the mouse not being released when hiding a `TextArea` while mouse selection is happening https://github.com/Textualize/textual/issues/4292
3637

3738
### Changed
3839

src/textual/widgets/_text_area.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,13 +1498,21 @@ async def _on_mouse_move(self, event: events.MouseMove) -> None:
14981498
selection_start, _ = self.selection
14991499
self.selection = Selection(selection_start, target)
15001500

1501-
async def _on_mouse_up(self, event: events.MouseUp) -> None:
1501+
def _end_mouse_selection(self) -> None:
15021502
"""Finalize the selection that has been made using the mouse."""
15031503
self._selecting = False
15041504
self.release_mouse()
15051505
self.record_cursor_width()
15061506
self._restart_blink()
15071507

1508+
async def _on_mouse_up(self, event: events.MouseUp) -> None:
1509+
"""Finalize the selection that has been made using the mouse."""
1510+
self._end_mouse_selection()
1511+
1512+
async def _on_hide(self, event: events.Hide) -> None:
1513+
"""Finalize the selection that has been made using the mouse when thew widget is hidden."""
1514+
self._end_mouse_selection()
1515+
15081516
async def _on_paste(self, event: events.Paste) -> None:
15091517
"""When a paste occurs, insert the text from the paste event into the document."""
15101518
if self.read_only:

0 commit comments

Comments
 (0)