diff --git a/CHANGELOG.md b/CHANGELOG.md index 71f24e0c75..cf10fd9640 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added `DOMNode.displayed_children` https://github.com/Textualize/textual/pull/6070 - Added `TextArea.UserInsert` message https://github.com/Textualize/textual/pull/6070 - Added `TextArea.hide_suggestion_on_blur` boolean https://github.com/Textualize/textual/pull/6070 +- Added `OptionList.highlighted_option` property https://github.com/Textualize/textual/pull/6090 +- Added `TextArea.update_suggestion` method https://github.com/Textualize/textual/pull/6090 ### Changed diff --git a/src/textual/widgets/_footer.py b/src/textual/widgets/_footer.py index 41a24ea514..d61e130816 100644 --- a/src/textual/widgets/_footer.py +++ b/src/textual/widgets/_footer.py @@ -256,6 +256,8 @@ def compose(self) -> ComposeResult: self.app.get_key_display(binding), "", binding.action, + disabled=not enabled, + tooltip=tooltip or binding.description, classes="-grouped", ).data_bind(Footer.compact) yield FooterLabel(group.description) diff --git a/src/textual/widgets/_option_list.py b/src/textual/widgets/_option_list.py index a7e8ddd379..52f06114b3 100644 --- a/src/textual/widgets/_option_list.py +++ b/src/textual/widgets/_option_list.py @@ -311,6 +311,18 @@ def option_count(self) -> int: """The number of options.""" return len(self._options) + @property + def highlighted_option(self) -> Option | None: + """The currently highlighted options, or `None` if no option is highlighted, + + Returns: + An Option, or `None`. + """ + if self.highlighted is not None: + return self.options[self.highlighted] + else: + return None + def clear_options(self) -> Self: """Clear the content of the option list. diff --git a/src/textual/widgets/_text_area.py b/src/textual/widgets/_text_area.py index edf1d2002b..880efc2fb7 100644 --- a/src/textual/widgets/_text_area.py +++ b/src/textual/widgets/_text_area.py @@ -663,9 +663,7 @@ def notify_style_update(self) -> None: super().notify_style_update() def update_suggestion(self) -> None: - """A hook called after edits, to allow subclasses to update the - [`suggestion`][textual.widgets.TextArea.suggestion] attribute. - """ + """A hook to update the [`suggestion`][textual.widgets.TextArea.suggestion] attribute.""" def check_consume_key(self, key: str, character: str | None = None) -> bool: """Check if the widget may consume the given key. @@ -1079,6 +1077,7 @@ def load_text(self, text: str) -> None: self.history.clear() self._set_document(text, self.language) self.post_message(self.Changed(self).set_sender(self)) + self.update_suggestion() def _on_resize(self) -> None: self._rewrap_and_refresh_virtual_size() @@ -1625,6 +1624,7 @@ def _undo_batch(self, edits: Sequence[Edit]) -> None: edit.after(self) self._build_highlight_map() self.post_message(self.Changed(self)) + self.update_suggestion() def _redo_batch(self, edits: Sequence[Edit]) -> None: """Redo a batch of Edits in order. @@ -1673,6 +1673,7 @@ def _redo_batch(self, edits: Sequence[Edit]) -> None: edit.after(self) self._build_highlight_map() self.post_message(self.Changed(self)) + self.update_suggestion() async def _on_key(self, event: events.Key) -> None: """Handle key presses which correspond to document inserts."""