Skip to content

Commit

Permalink
Simplify on_key even further
Browse files Browse the repository at this point in the history
  • Loading branch information
anze3db committed Jan 18, 2024
1 parent ae9f40a commit 182965f
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions src/django_tui/management/commands/ish.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,16 @@ class ExtendedTextArea(TextArea):
"""A subclass of TextArea with parenthesis-closing functionality."""

def _on_key(self, event: events.Key) -> None:
chars = [
{
"char":"(",
"closing":")"
},
{
"char":"{",
"closing":"}"
},
{
"char":"[",
"closing":"]"
},
{
"char":"'",
"closing":"'"
},
{
"char":'"',
"closing":'"'
},
]
event_char_list = list(filter(lambda item: item["char"] == event.character, chars))
if len(event_char_list) > 0:
self.insert(f"{event_char_list[0]['char']}{event_char_list[0]['closing']}")
auto_close_chars = {
"(": ")",
"{": "}",
"[": "]",
"'": "'",
'"': '"',
}
closing_char = auto_close_chars.get(event.character)
if closing_char:
self.insert(f"{event.character}{closing_char}")
self.move_cursor_relative(columns=-1)
event.prevent_default()

Expand Down

0 comments on commit 182965f

Please sign in to comment.