Skip to content

Commit

Permalink
Merge pull request #4295 from davep/ungreedyify-textarea
Browse files Browse the repository at this point in the history
Fix `TextArea` holding on to focus when hidden while doing a mouse selection
  • Loading branch information
davep authored Mar 14, 2024
2 parents 8c0077a + 96ee503 commit 6b8790e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion src/textual/widgets/_text_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6b8790e

Please sign in to comment.