Handle Y/n keys at app level for approval, bypassing widget focus issues
- SHA
d66908dfc4dba316b74c47855bc95ee41c23530d- Parents
-
79dc7fb - Tree
c65d2f6
d66908d
d66908dfc4dba316b74c47855bc95ee41c23530d79dc7fb
c65d2f6| Status | File | + | - |
|---|---|---|---|
| M |
src/loader/ui/app.py
|
20 | 0 |
src/loader/ui/app.pymodified@@ -432,6 +432,26 @@ class LoaderApp(App): | ||
| 432 | 432 | finally: |
| 433 | 433 | self._pending_question = None |
| 434 | 434 | |
| 435 | + def on_key(self, event) -> None: | |
| 436 | + """Intercept Y/n/e keys at app level when a confirmation is pending. | |
| 437 | + | |
| 438 | + This bypasses the approval bar focus issue — the bar may not receive | |
| 439 | + focus reliably, so we handle the keys here instead. | |
| 440 | + """ | |
| 441 | + if self._pending_confirmation is None or self._pending_confirmation.done(): | |
| 442 | + return | |
| 443 | + key = event.key | |
| 444 | + if key in ("y", "Y"): | |
| 445 | + event.prevent_default() | |
| 446 | + event.stop() | |
| 447 | + self._pending_confirmation.set_result(True) | |
| 448 | + self.query_one("#approval-bar", ApprovalBar).hide_approval() | |
| 449 | + elif key in ("n", "N", "escape"): | |
| 450 | + event.prevent_default() | |
| 451 | + event.stop() | |
| 452 | + self._pending_confirmation.set_result(False) | |
| 453 | + self.query_one("#approval-bar", ApprovalBar).hide_approval() | |
| 454 | + | |
| 435 | 455 | def on_approval_bar_approved(self, event: ApprovalBar.Approved) -> None: |
| 436 | 456 | """Handle approval from the bar.""" |
| 437 | 457 | try: |