From 1f3e9493b1695e4f94f1c3c20d9b8f8249ec7285 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 20 Jul 2025 09:38:34 +0300 Subject: feat: add ESC key support for all dialogs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- internal/gui/app.go | 40 ++++++++++++++++++++++++++++++++++------ 1 file 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() -- cgit v1.2.3