Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TextArea holding on to focus when hidden while doing a mouse selection #4295

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Comment on lines +1508 to +1512
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two should definitely be in reverse order. 🙄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did that to be annoying. :-P

"""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
Loading