Skip to content

Commit

Permalink
Merge pull request #4211 from Textualize/content-cache-fix
Browse files Browse the repository at this point in the history
Fix content size cache
  • Loading branch information
willmcgugan authored Feb 26, 2024
2 parents a2b72c5 + 22a413d commit 7327987
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Tooltips are now cleared when the related widget is no longer under them https://github.com/Textualize/textual/issues/3045
- Simplified tree-sitter highlight queries for HTML, which also seems to fix segfault issue https://github.com/Textualize/textual/pull/4195
- Fixed `DirectoryTree.path` no longer reacting to new values https://github.com/Textualize/textual/issues/4208
- Fixed content size cache with Pretty widget https://github.com/Textualize/textual/pull/4211

## [0.52.1] - 2024-02-20

Expand Down
16 changes: 14 additions & 2 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,19 @@ def __exit__(
else:
self.app._composed[-1].append(composed)

def clear_cached_dimensions(self) -> None:
"""Clear cached results of `get_content_width` and `get_content_height`.
Call if the widget's renderable changes size after the widget has been created.
!!! note
This is not required if you are extending [`Static`][textual.widgets.Static].
"""
self._content_width_cache = (None, 0)
self._content_height_cache = (None, 0)

def get_loading_widget(self) -> Widget:
"""Get a widget to display a loading indicator.
Expand Down Expand Up @@ -3278,8 +3291,7 @@ def refresh(

if repaint:
self._set_dirty(*regions)
self._content_width_cache = (None, 0)
self._content_height_cache = (None, 0)
self.clear_cached_dimensions()
self._rich_style_cache.clear()
self._repaint_required = True

Expand Down
1 change: 1 addition & 0 deletions src/textual/widgets/_pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ def update(self, object: Any) -> None:
object: The object to pretty-print.
"""
self._renderable = PrettyRenderable(object)
self.clear_cached_dimensions()
self.refresh(layout=True)
1 change: 1 addition & 0 deletions src/textual/widgets/_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def renderable(self, renderable: RenderableType) -> None:
self._renderable = Text(renderable)
else:
self._renderable = renderable
self.clear_cached_dimensions()

def render(self) -> RenderableType:
"""Get a rich renderable for the widget's content.
Expand Down

0 comments on commit 7327987

Please sign in to comment.