diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c47a9c0c6..097ac54b65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.12.1] - 2023-02-25 + +### Fixed + +- Fix for batch update glitch https://github.com/Textualize/textual/pull/1880 + ## [0.12.0] - 2023-02-24 ### Added diff --git a/pyproject.toml b/pyproject.toml index 97694cc230..75e03a1554 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "textual" -version = "0.12.0" +version = "0.12.1" homepage = "https://github.com/Textualize/textual" description = "Modern Text User Interface framework" authors = ["Will McGugan "] diff --git a/src/textual/_styles_cache.py b/src/textual/_styles_cache.py index c760fcfe3f..1082f4c054 100644 --- a/src/textual/_styles_cache.py +++ b/src/textual/_styles_cache.py @@ -8,10 +8,10 @@ from rich.style import Style from ._border import get_box, render_row -from .filter import LineFilter from ._opacity import _apply_opacity from ._segment_tools import line_pad, line_trim from .color import Color +from .filter import LineFilter from .geometry import Region, Size, Spacing from .renderables.text_opacity import TextOpacity from .renderables.tint import Tint @@ -120,13 +120,12 @@ def render_widget(self, widget: Widget, crop: Region) -> list[Strip]: ) if widget.auto_links: hover_style = widget.hover_style - link_hover_style = widget.link_hover_style if ( - link_hover_style - and hover_style._link_id + hover_style._link_id and hover_style._meta and "@click" in hover_style.meta ): + link_hover_style = widget.link_hover_style if link_hover_style: strips = [ strip.style_links(hover_style.link_id, link_hover_style) diff --git a/src/textual/app.py b/src/textual/app.py index 44d20e76f5..e49812f011 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -460,10 +460,6 @@ def _end_batch(self) -> None: self._batch_count -= 1 assert self._batch_count >= 0, "This won't happen if you use `batch_update`" if not self._batch_count: - try: - self.screen.check_idle() - except ScreenStackError: - pass self.check_idle() def animate( diff --git a/src/textual/strip.py b/src/textual/strip.py index 53d8a8e9f2..9b82db01d1 100644 --- a/src/textual/strip.py +++ b/src/textual/strip.py @@ -9,8 +9,8 @@ from rich.style import Style, StyleType from ._cache import FIFOCache -from .filter import LineFilter from ._segment_tools import index_to_cell_position +from .filter import LineFilter @rich.repr.auto @@ -29,6 +29,7 @@ class Strip: "_cell_length", "_divide_cache", "_crop_cache", + "_link_ids", ] def __init__( @@ -38,6 +39,7 @@ def __init__( self._cell_length = cell_length self._divide_cache: FIFOCache[tuple[int, ...], list[Strip]] = FIFOCache(4) self._crop_cache: FIFOCache[tuple[int, int], Strip] = FIFOCache(4) + self._link_ids: set[str] | None = None def __rich_repr__(self) -> rich.repr.Result: yield self._segments @@ -48,6 +50,15 @@ def text(self) -> str: """Segment text.""" return "".join(segment.text for segment in self._segments) + @property + def link_ids(self) -> set[str]: + """A set of the link ids in this Strip.""" + if self._link_ids is None: + self._link_ids = { + style._link_id for _, style, _ in self._segments if style is not None + } + return self._link_ids + @classmethod def blank(cls, cell_length: int, style: StyleType | None = None) -> Strip: """Create a blank strip. @@ -230,19 +241,18 @@ def style_links(self, link_id: str, link_style: Style) -> Strip: Returns: New strip (or same Strip if no changes). """ + _Segment = Segment - if not any( - segment.style._link_id == link_id - for segment in self._segments - if segment.style - ): + if link_id not in self.link_ids: return self segments = [ _Segment( text, - (style + link_style if style is not None else None) - if (style and not style._null and style._link_id == link_id) - else style, + ( + (style + link_style if style is not None else None) + if (style and not style._null and style._link_id == link_id) + else style + ), control, ) for text, style, control in self._segments