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

prevent error in TextArea constructor #5045

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed
### [0.80.1] - 2024-09-24

- Fixed crash when exiting the app prematurely https://github.com/Textualize/textual/pull/5039
- Fixed exception constructing TextArea outside of App https://github.com/Textualize/textual/pull/5045

## [0.80.0] - 2024-09-23

Expand Down Expand Up @@ -2387,6 +2388,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
- New handler system for messages that doesn't require inheritance
- Improved traceback handling

[0.80.1]: https://github.com/Textualize/textual/compare/v0.80.0...v0.80.1
[0.80.0]: https://github.com/Textualize/textual/compare/v0.79.0...v0.80.0
[0.79.0]: https://github.com/Textualize/textual/compare/v0.78.0...v0.79.0
[0.78.0]: https://github.com/Textualize/textual/compare/v0.77.0...v0.78.0
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "textual"
version = "0.80.0"
version = "0.80.1"
homepage = "https://github.com/Textualize/textual"
repository = "https://github.com/Textualize/textual"
documentation = "https://textual.textualize.io/"
Expand Down
10 changes: 7 additions & 3 deletions src/textual/widgets/_text_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,6 @@ def __init__(

self.tab_behavior = tab_behavior

# When `app.dark` is toggled, reset the theme (since it caches values).
self.watch(self.app, "dark", self._app_dark_toggled, init=False)

if tooltip is not None:
self.tooltip = tooltip

Expand Down Expand Up @@ -610,6 +607,10 @@ def _watch_selection(
) -> None:
"""When the cursor moves, scroll it into view."""
# Find the visual offset of the cursor in the document

if not self.is_mounted:
return

cursor_location = selection.end

self.scroll_cursor_visible()
Expand Down Expand Up @@ -1519,6 +1520,9 @@ def gutter_width(self) -> int:
return gutter_width

def _on_mount(self, event: events.Mount) -> None:
# When `app.dark` is toggled, reset the theme (since it caches values).
self.watch(self.app, "dark", self._app_dark_toggled, init=False)

self.blink_timer = self.set_interval(
0.5,
self._toggle_cursor_blink_visible,
Expand Down
41 changes: 40 additions & 1 deletion tests/test_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,46 @@
from textual.geometry import Offset, Size
from textual.message import Message
from textual.widget import BadWidgetName, MountError, PseudoClasses, Widget
from textual.widgets import Label, LoadingIndicator
from textual.widgets import (
Button,
DataTable,
Footer,
Header,
Input,
Label,
LoadingIndicator,
Log,
OptionList,
RichLog,
Switch,
TextArea,
)


async def test_widget_construct():
"""Regression test for https://github.com/Textualize/textual/issues/5042"""

# Check that constructing the widget outside of the app, doesn't invoke code that
# expects an active app.
class MyApp(App):
def __init__(self) -> None:
super().__init__()
self.button = Button()
self.data_table = DataTable()
self.footer = Footer()
self.header = Header()
self.input = Input()
self.label = Label()
self.loading_indicator = LoadingIndicator()
self.log = Log()
self.option_list = OptionList()
self.rich_log = RichLog()
self.switch = Switch()
self.text_area = TextArea(language="python")

app = MyApp()
async with app.run_test():
pass


@pytest.mark.parametrize(
Expand Down
Loading