From 89557e28928401007fa1a04ad5322d985a25d65f Mon Sep 17 00:00:00 2001 From: drew Date: Wed, 3 Jun 2026 16:52:14 +0400 Subject: [PATCH] fix: save drafts on quit Signed-off-by: drew --- main.go | 7 +++++++ tui/composer.go | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/main.go b/main.go index 07db297..c7918ea 100644 --- a/main.go +++ b/main.go @@ -340,6 +340,13 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:gocyclo switch msg := msg.(type) { case tea.KeyPressMsg: if msg.String() == "ctrl+c" { + // Persist an in-progress draft so quitting the composer + // doesn't discard the user's work. + if composer, ok := m.current.(*tui.Composer); ok && composer.HasContent() { + if err := config.SaveDraft(composer.ToDraft()); err != nil { + log.Printf("Error saving draft on quit: %v", err) + } + } m.idleWatcher.StopAll() if m.service != nil { m.service.Close() //nolint:errcheck,gosec diff --git a/tui/composer.go b/tui/composer.go index 2e032b0..52f573a 100644 --- a/tui/composer.go +++ b/tui/composer.go @@ -1528,6 +1528,15 @@ func (m *Composer) HidePluginPrompt() { m.showPluginPrompt = false } +// HasContent reports whether the composer holds anything worth persisting. +// It is used to avoid saving empty drafts when the user quits the composer. +func (m *Composer) HasContent() bool { + return m.hasAnyRecipient() || + strings.TrimSpace(m.subjectInput.Value()) != "" || + strings.TrimSpace(m.bodyInput.Value()) != "" || + len(m.attachmentPaths) > 0 +} + // ToDraft converts the composer state to a Draft for saving. func (m *Composer) ToDraft() config.Draft { return config.Draft{