Skip to content

Commit f3f385d

Browse files
authored
Merge pull request #6090 from Textualize/update-suggestion
update suggestion method
2 parents cfcdaef + d34fc26 commit f3f385d

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2626
- Added `DOMNode.displayed_children` https://github.com/Textualize/textual/pull/6070
2727
- Added `TextArea.UserInsert` message https://github.com/Textualize/textual/pull/6070
2828
- Added `TextArea.hide_suggestion_on_blur` boolean https://github.com/Textualize/textual/pull/6070
29+
- Added `OptionList.highlighted_option` property https://github.com/Textualize/textual/pull/6090
30+
- Added `TextArea.update_suggestion` method https://github.com/Textualize/textual/pull/6090
2931

3032
### Changed
3133

src/textual/widgets/_footer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ def compose(self) -> ComposeResult:
256256
self.app.get_key_display(binding),
257257
"",
258258
binding.action,
259+
disabled=not enabled,
260+
tooltip=tooltip or binding.description,
259261
classes="-grouped",
260262
).data_bind(Footer.compact)
261263
yield FooterLabel(group.description)

src/textual/widgets/_option_list.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,18 @@ def option_count(self) -> int:
311311
"""The number of options."""
312312
return len(self._options)
313313

314+
@property
315+
def highlighted_option(self) -> Option | None:
316+
"""The currently highlighted options, or `None` if no option is highlighted,
317+
318+
Returns:
319+
An Option, or `None`.
320+
"""
321+
if self.highlighted is not None:
322+
return self.options[self.highlighted]
323+
else:
324+
return None
325+
314326
def clear_options(self) -> Self:
315327
"""Clear the content of the option list.
316328

src/textual/widgets/_text_area.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,7 @@ def notify_style_update(self) -> None:
663663
super().notify_style_update()
664664

665665
def update_suggestion(self) -> None:
666-
"""A hook called after edits, to allow subclasses to update the
667-
[`suggestion`][textual.widgets.TextArea.suggestion] attribute.
668-
"""
666+
"""A hook to update the [`suggestion`][textual.widgets.TextArea.suggestion] attribute."""
669667

670668
def check_consume_key(self, key: str, character: str | None = None) -> bool:
671669
"""Check if the widget may consume the given key.
@@ -1079,6 +1077,7 @@ def load_text(self, text: str) -> None:
10791077
self.history.clear()
10801078
self._set_document(text, self.language)
10811079
self.post_message(self.Changed(self).set_sender(self))
1080+
self.update_suggestion()
10821081

10831082
def _on_resize(self) -> None:
10841083
self._rewrap_and_refresh_virtual_size()
@@ -1625,6 +1624,7 @@ def _undo_batch(self, edits: Sequence[Edit]) -> None:
16251624
edit.after(self)
16261625
self._build_highlight_map()
16271626
self.post_message(self.Changed(self))
1627+
self.update_suggestion()
16281628

16291629
def _redo_batch(self, edits: Sequence[Edit]) -> None:
16301630
"""Redo a batch of Edits in order.
@@ -1673,6 +1673,7 @@ def _redo_batch(self, edits: Sequence[Edit]) -> None:
16731673
edit.after(self)
16741674
self._build_highlight_map()
16751675
self.post_message(self.Changed(self))
1676+
self.update_suggestion()
16761677

16771678
async def _on_key(self, event: events.Key) -> None:
16781679
"""Handle key presses which correspond to document inserts."""

0 commit comments

Comments
 (0)