From 6bd53b1acaa6f9d186e4b851eb32d0d225cdf561 Mon Sep 17 00:00:00 2001 From: FromSi Date: Thu, 7 May 2026 11:38:02 +0500 Subject: [PATCH] fix(tui): stop attachment nav scroll (#1243) ## What? Prevents email body scrolling when navigating attachments in the email view. ## Why? When attachment focus is active, up/down should only move the attachment selection. Previously, those key events also reached the email body viewport, causing the message content to scroll at the same time. --- tui/email_view.go | 2 ++ tui/email_view_test.go | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tui/email_view.go b/tui/email_view.go index 165f4bb73e5b5f886eecb9bfb72bf77bab6575f3..978092a85dbc774ecaeb1c3bb3806e6fa11f1259 100644 --- a/tui/email_view.go +++ b/tui/email_view.go @@ -209,10 +209,12 @@ func (m *EmailView) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.attachmentCursor > 0 { m.attachmentCursor-- } + return m, nil case "down", kb.Global.NavDown: if m.attachmentCursor < len(m.email.Attachments)-1 { m.attachmentCursor++ } + return m, nil case "enter": if len(m.email.Attachments) > 0 { selected := m.email.Attachments[m.attachmentCursor] diff --git a/tui/email_view_test.go b/tui/email_view_test.go index 80233a2b01451a8f9dd7b848f2c04ff04de56efe..18f825ff3c62cc122951c89dde247708a30f2032 100644 --- a/tui/email_view_test.go +++ b/tui/email_view_test.go @@ -94,6 +94,26 @@ func TestEmailViewUpdate(t *testing.T) { } }) + t.Run("Attachment navigation does not scroll body", func(t *testing.T) { + emailView := NewEmailView(emailWithAttachments, 0, 80, 24, MailboxInbox, false) + emailView.viewport.SetHeight(2) + emailView.viewport.SetContent("line 1\nline 2\nline 3\nline 4\nline 5\n") + emailView.viewport.SetYOffset(1) + + model, _ := emailView.Update(tea.KeyPressMsg{Code: tea.KeyTab}) + emailView = model.(*EmailView) + if !emailView.focusOnAttachments { + t.Fatal("focusOnAttachments should be true after tabbing") + } + + before := emailView.viewport.YOffset() + model, _ = emailView.Update(tea.KeyPressMsg{Code: tea.KeyDown}) + emailView = model.(*EmailView) + if got := emailView.viewport.YOffset(); got != before { + t.Fatalf("attachment navigation should not scroll the email body, got offset %d want %d", got, before) + } + }) + t.Run("Download attachment", func(t *testing.T) { emailView := NewEmailView(emailWithAttachments, 0, 80, 24, MailboxInbox, false) // Focus on attachments