Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tui/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading