Skip to content

Commit a272105

Browse files
committed
fix select
1 parent faac1a3 commit a272105

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/textual/widgets/_option_list.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ def _add_lines(
363363

364364
self.virtual_size = Size(width, len(self._lines))
365365
self.refresh(layout=self.styles.auto_dimensions)
366+
self._scroll_update(self.virtual_size)
366367

367368
def _populate(self) -> None:
368369
"""Populate the lines data-structure."""
@@ -879,9 +880,12 @@ def scroll_to_highlight(self, top: bool = False) -> None:
879880
top: Scroll highlight to top of the list.
880881
"""
881882
highlighted = self.highlighted
882-
if highlighted is None or self._spans is None:
883+
if highlighted is None or not self.is_mounted:
883884
return
884885

886+
if not self._spans:
887+
self._populate()
888+
885889
try:
886890
y, height = self._spans[highlighted]
887891
except IndexError:
@@ -894,6 +898,7 @@ def scroll_to_highlight(self, top: bool = False) -> None:
894898
force=True,
895899
animate=False,
896900
top=top,
901+
immediate=True,
897902
)
898903

899904
def validate_highlighted(self, highlighted: int | None) -> int | None:

src/textual/widgets/_select.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def select(self, index: int | None) -> None:
6666
index: Index of new selection.
6767
"""
6868
self.highlighted = index
69-
self.scroll_to_highlight(top=True)
69+
self.scroll_to_highlight()
7070

7171
def action_dismiss(self) -> None:
7272
"""Dismiss the overlay."""
@@ -520,7 +520,7 @@ def _watch_expanded(self, expanded: bool) -> None:
520520
value = self.value
521521
for index, (_prompt, prompt_value) in enumerate(self._options):
522522
if value == prompt_value:
523-
overlay.select(index)
523+
self.call_after_refresh(overlay.select, index)
524524
break
525525
self.query_one(SelectCurrent).has_value = True
526526

0 commit comments

Comments
 (0)