diff options
| author | Paul Buetow <paul@buetow.org> | 2025-07-20 09:38:34 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-07-20 09:38:34 +0300 |
| commit | 1f3e9493b1695e4f94f1c3c20d9b8f8249ec7285 (patch) | |
| tree | 2859cd49d8ffddde388fdfcfa6a5decdadbcf703 | |
| parent | ff01e800a6633b74050c6f75e5798736c93743b4 (diff) | |
feat: add ESC key support for all dialogs
- Added ESC key to close help dialog
- Added ESC key to close/cancel export dialog
- Updated dialog instructions to show ESC option
- ESC already supported for delete confirmation and unfocusing text areas
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
| -rw-r--r-- | internal/gui/app.go | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/internal/gui/app.go b/internal/gui/app.go index a6f4eec..5a43c5c 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -974,7 +974,7 @@ func (a *Application) onExportToAnki() { // Store export dialog state exportDialogOpen := true - customDialog := dialog.NewCustomConfirm("Export to Anki", "Export (e)", "Cancel (c)", content, func(export bool) { + customDialog := dialog.NewCustomConfirm("Export to Anki", "Export (e)", "Cancel (c/Esc)", content, func(export bool) { exportDialogOpen = false if !export { return @@ -1046,8 +1046,9 @@ func (a *Application) onExportToAnki() { } }, a.window) - // Store original keyboard handler + // Store original keyboard handlers originalRuneHandler := a.window.Canvas().OnTypedRune() + originalKeyHandler := a.window.Canvas().OnTypedKey() // Add keyboard shortcuts for the export dialog (both Latin and Cyrillic) a.window.Canvas().SetOnTypedRune(func(r rune) { @@ -1071,11 +1072,25 @@ func (a *Application) onExportToAnki() { } }) - // Restore original handler when dialog closes + // Add ESC key handler + a.window.Canvas().SetOnTypedKey(func(ev *fyne.KeyEvent) { + if exportDialogOpen && ev.Name == fyne.KeyEscape { + customDialog.Hide() + exportDialogOpen = false + return + } + // Call original handler if it exists + if originalKeyHandler != nil { + originalKeyHandler(ev) + } + }) + + // Restore original handlers when dialog closes customDialog.SetOnClosed(func() { exportDialogOpen = false - // Restore original keyboard handler + // Restore original keyboard handlers a.window.Canvas().SetOnTypedRune(originalRuneHandler) + a.window.Canvas().SetOnTypedKey(originalKeyHandler) }) customDialog.Resize(fyne.NewSize(400, 300)) @@ -1122,7 +1137,7 @@ func (a *Application) onShowHotkeys() { --- *All hotkeys work with both Latin and Cyrillic keyboards* -Press **c/ц** to close this dialog` +Press **c/ц** or **Esc** to close this dialog` content := widget.NewRichTextFromMarkdown(hotkeys) content.Wrapping = fyne.TextWrapWord @@ -1140,8 +1155,9 @@ Press **c/ц** to close this dialog` // Store dialog state dialogOpen := true - // Store original rune handler + // Store original handlers originalRuneHandler := a.window.Canvas().OnTypedRune() + originalKeyHandler := a.window.Canvas().OnTypedKey() // Add temporary handler for 'c' to close dialog (both Latin and Cyrillic) a.window.Canvas().SetOnTypedRune(func(r rune) { @@ -1155,6 +1171,18 @@ Press **c/ц** to close this dialog` } }) + // Add ESC key handler + a.window.Canvas().SetOnTypedKey(func(ev *fyne.KeyEvent) { + if dialogOpen && ev.Name == fyne.KeyEscape { + d.Hide() + return + } + // Call original handler if it exists + if originalKeyHandler != nil { + originalKeyHandler(ev) + } + }) + // Show the dialog d.Show() |
