summary refs log tree commit diff stats
path: root/widgets/msgviewer.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-20 16:49:39 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-20 16:49:39 -0400
commit0897413a3e7b7707e6e597077d1621e586180f3b (patch)
tree80ca6a98af958817dcc0847c5e5dd3af091dcc86 /widgets/msgviewer.go
parent511fea39449b6db551151da86d914bf7ab3b3713 (diff)
downloadaerc-0897413a3e7b7707e6e597077d1621e586180f3b.tar.gz
Implement :next-part, :prev-part
Diffstat (limited to 'widgets/msgviewer.go')
-rw-r--r--widgets/msgviewer.go33
1 files changed, 31 insertions, 2 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index ab79b5e..64762f7 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -119,12 +119,13 @@ func NewMessageViewer(conf *config.AercConfig,
 		if err != nil {
 			goto handle_error
 		}
+		switcher.selected = -1
 		for i, pv := range switcher.parts {
 			pv.OnInvalidate(func(_ ui.Drawable) {
 				switcher.Invalidate()
 			})
 			// TODO: switch to user's preferred mimetype, if configured
-			if switcher.selected == 0 && pv.part.MIMEType != "multipart" {
+			if switcher.selected == -1 && pv.part.MIMEType != "multipart" {
 				switcher.selected = i
 			}
 		}
@@ -198,6 +199,34 @@ func (mv *MessageViewer) OnInvalidate(fn func(d ui.Drawable)) {
 	})
 }
 
+func (mv *MessageViewer) PreviousPart() {
+	switcher := mv.switcher
+	for {
+		switcher.selected--
+		if switcher.selected < 0 {
+			switcher.selected = len(switcher.parts) - 1
+		}
+		if switcher.parts[switcher.selected].part.MIMEType != "multipart" {
+			break
+		}
+	}
+	mv.Invalidate()
+}
+
+func (mv *MessageViewer) NextPart() {
+	switcher := mv.switcher
+	for {
+		switcher.selected++
+		if switcher.selected >= len(switcher.parts) {
+			switcher.selected = 0
+		}
+		if switcher.parts[switcher.selected].part.MIMEType != "multipart" {
+			break
+		}
+	}
+	mv.Invalidate()
+}
+
 func (ps *PartSwitcher) Invalidate() {
 	ps.DoInvalidate(ps)
 }
@@ -318,7 +347,7 @@ func NewPartViewer(conf *config.AercConfig,
 
 	pv := &PartViewer{
 		filter:  filter,
-		index:   index, // TODO: Nested multipart does indicies differently
+		index:   index,
 		msg:     msg,
 		pager:   pager,
 		pagerin: pagerin,