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

batch update fix, and optimization #1880

Merged
merged 3 commits into from
Feb 25, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.12.0"
version = "0.12.1"
homepage = "https://github.com/Textualize/textual"
description = "Modern Text User Interface framework"
authors = ["Will McGugan <[email protected]>"]
Expand Down
7 changes: 3 additions & 4 deletions src/textual/_styles_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 19 additions & 9 deletions src/textual/strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +29,7 @@ class Strip:
"_cell_length",
"_divide_cache",
"_crop_cache",
"_link_ids",
]

def __init__(
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down