Skip to content

Commit

Permalink
Enhance TemplateSelectModal with default template selection and keybo…
Browse files Browse the repository at this point in the history
…ard navigation
  • Loading branch information
royshil committed Nov 7, 2024
1 parent e515c12 commit 8d96d83
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/template_select_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ def _load_template_names(self):
def compose(self):
yield Container(
Static("Select a template:"),
Select(options=self.templates, id="template_select"),
Select(
options=self.templates, value=self.templates[1][1], id="template_select"
),
Button("Confirm", variant="primary", id="confirm"),
Button("Cancel", variant="default", id="cancel"),
classes="template-modal",
)

def _on_mount(self, event):
self.focus_next("#confirm")
return super()._on_mount(event)

def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "confirm":
selected = self.query_one("#template_select").value
Expand All @@ -39,3 +45,11 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
self.dismiss((False, None))
else:
self.dismiss((False, None))

def _on_key(self, event):
if event.key == "escape":
self.dismiss((False, None))
# stop the bubbling of the event
event.stop()
return
return super()._on_key(event)

0 comments on commit 8d96d83

Please sign in to comment.