Skip to content

Commit 2c15baf

Browse files
authored
Merge pull request #5740 from Textualize/optimize-ol
Optimize Option List style change
2 parents 1240288 + 85d919a commit 2c15baf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/textual/widgets/_option_list.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from textual.binding import Binding, BindingType
1212
from textual.cache import LRUCache
1313
from textual.css.styles import RulesMap
14-
from textual.geometry import Region, Size, clamp
14+
from textual.geometry import Region, Size, Spacing, clamp
1515
from textual.message import Message
1616
from textual.reactive import reactive
1717
from textual.scroll_view import ScrollView
@@ -272,7 +272,7 @@ def __init__(
272272
self._option_to_index: dict[Option, int] = {}
273273
"""Maps an Option to it's index in self._options."""
274274

275-
self._option_render_cache: LRUCache[tuple[Option, Style], list[Strip]]
275+
self._option_render_cache: LRUCache[tuple[Option, Style, Spacing], list[Strip]]
276276
self._option_render_cache = LRUCache(maxsize=1024 * 2)
277277
"""Caches rendered options."""
278278

@@ -658,7 +658,7 @@ def _clear_caches(self) -> None:
658658
self.refresh()
659659

660660
def notify_style_update(self) -> None:
661-
self._clear_caches()
661+
self.refresh()
662662
super().notify_style_update()
663663

664664
def _on_resize(self):
@@ -741,7 +741,7 @@ def _get_option_render(self, option: Option, style: Style) -> list[Strip]:
741741
padding = self.get_component_styles("option-list--option").padding
742742
render_width = self.scrollable_content_region.width
743743
width = render_width - self._get_left_gutter_width()
744-
cache_key = (option, style)
744+
cache_key = (option, style, padding)
745745
if (strips := self._option_render_cache.get(cache_key)) is None:
746746
visual = self._get_visual(option)
747747
if padding:

0 commit comments

Comments
 (0)