From d6f2498dbdfe7a92cb5ff469116df955ff204d3c Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Thu, 15 Jun 2023 09:52:28 -0400 Subject: [PATCH] fix: escape attachments --- keymap.go | 7 +++++++ model.go | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/keymap.go b/keymap.go index 26832f6..b6709cf 100644 --- a/keymap.go +++ b/keymap.go @@ -9,6 +9,7 @@ type KeyMap struct { Send key.Binding Attach key.Binding Unattach key.Binding + Back key.Binding Quit key.Binding } @@ -36,6 +37,11 @@ func DefaultKeybinds() KeyMap { key.WithHelp("x", "remove"), key.WithDisabled(), ), + Back: key.NewBinding( + key.WithKeys("esc"), + key.WithHelp("esc", "back"), + key.WithDisabled(), + ), Quit: key.NewBinding( key.WithKeys("ctrl+c"), key.WithHelp("ctrl+c", "quit"), @@ -64,4 +70,5 @@ func (m *Model) updateKeymap() { canSend := m.From.Value() != "" && m.To.Value() != "" && m.Subject.Value() != "" && m.Body.Value() != "" m.keymap.Send.SetEnabled(canSend && m.state != editingBody && m.state != pickingFile) m.keymap.Unattach.SetEnabled(m.state == editingAttachments && len(m.Attachments.Items()) > 0) + m.keymap.Back.SetEnabled(m.state == pickingFile) } diff --git a/model.go b/model.go index 3df21f2..0f711e5 100644 --- a/model.go +++ b/model.go @@ -127,7 +127,6 @@ func NewModel() Model { func (m Model) Init() tea.Cmd { return tea.Batch( m.From.Cursor.BlinkCmd(), - m.filepicker.Init(), ) } @@ -174,6 +173,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } m.focusActiveInput() + case key.Matches(msg, m.keymap.Back): + m.state = editingAttachments + m.updateKeymap() + return m, nil case key.Matches(msg, m.keymap.Send): m.state = sendingEmail return m, tea.Batch( @@ -182,6 +185,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { ) case key.Matches(msg, m.keymap.Attach): m.state = pickingFile + return m, m.filepicker.Init() case key.Matches(msg, m.keymap.Unattach): m.Attachments.RemoveItem(m.Attachments.Index()) m.Attachments.SetHeight(max(len(m.Attachments.Items()), 1) + 2) @@ -276,7 +280,7 @@ func (m Model) View() string { switch m.state { case pickingFile: - return "\n" + activeLabelStyle.Render("Attachments") + + return "\n" + activeLabelStyle.Render("Attachments") + " " + commentStyle.Render(m.filepicker.CurrentDirectory) + "\n\n" + m.filepicker.View() case sendingEmail: return "\n " + m.loadingSpinner.View() + "Sending email"