textual/docs/examples/widgets/text_area_extended.py
TomJGooding ca2c11bdb8
docs(text area): fix syntax highlighting in examples (#4099)
* docs(text area): fix syntax highlighting in examples

* revert text_area_extended.py

* fix class method

* fix extended text area example
2024-02-05 10:33:22 +00:00

23 lines
627 B
Python

from textual import events
from textual.app import App, ComposeResult
from textual.widgets import TextArea
class ExtendedTextArea(TextArea):
"""A subclass of TextArea with parenthesis-closing functionality."""
def _on_key(self, event: events.Key) -> None:
if event.character == "(":
self.insert("()")
self.move_cursor_relative(columns=-1)
event.prevent_default()
class TextAreaKeyPressHook(App):
def compose(self) -> ComposeResult:
yield ExtendedTextArea.code_editor(language="python")
app = TextAreaKeyPressHook()
if __name__ == "__main__":
app.run()