aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-01-29 23:52:28 +0100
committerRobin Jarry <robin@jarry.cc>2024-02-11 22:03:56 +0100
commit05874f867c76c8e9b8c1e67a57dc702e63d6d54b (patch)
treeedb8ba9a4800511f30810c5be90a709df695147e /app
parent635fe05d4e8ee5a6dbadf7d10b6d8340efcbc84d (diff)
downloadaerc-05874f867c76c8e9b8c1e67a57dc702e63d6d54b.tar.gz
aerc-05874f867c76c8e9b8c1e67a57dc702e63d6d54b.zip
commands: add align
Add a new :align command that aligns the selected message vertically at the top, center, or bottom of the message list. The command requires a position argument that can either be: "top", "center", or "bottom". Create the following default keybinds: zz = :align center<Enter> zt = :align top<Enter> zb = :align bottom<Enter> Changelog-added: Add new `:align` command to align the selected message at the top, center, or bottom of the message list. Suggested-by: Ángel Castañeda <angel@acsq.me> Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'app')
-rw-r--r--app/msglist.go17
-rw-r--r--app/scrollable.go24
2 files changed, 41 insertions, 0 deletions
diff --git a/app/msglist.go b/app/msglist.go
index a5e5fbb6..38970123 100644
--- a/app/msglist.go
+++ b/app/msglist.go
@@ -51,6 +51,23 @@ type messageRowParams struct {
headers *mail.Header
}
+// AlignMessage aligns the selected message to position pos.
+func (ml *MessageList) AlignMessage(pos AlignPosition) {
+ store := ml.Store()
+ if store == nil {
+ return
+ }
+ idx := 0
+ iter := store.UidsIterator()
+ for i := 0; iter.Next(); i++ {
+ if store.SelectedUid() == iter.Value().(uint32) {
+ idx = i
+ break
+ }
+ }
+ ml.Align(idx, pos)
+}
+
func (ml *MessageList) Draw(ctx *ui.Context) {
ml.height = ctx.Height()
ml.width = ctx.Width()
diff --git a/app/scrollable.go b/app/scrollable.go
index 3a0555fe..04436375 100644
--- a/app/scrollable.go
+++ b/app/scrollable.go
@@ -62,6 +62,10 @@ func (s *Scrollable) EnsureScroll(idx int) {
s.scroll = idx + s.offset - s.height + 1
}
+ s.checkBounds()
+}
+
+func (s *Scrollable) checkBounds() {
maxScroll := s.elems - s.height
if maxScroll < 0 {
maxScroll = 0
@@ -75,3 +79,23 @@ func (s *Scrollable) EnsureScroll(idx int) {
s.scroll = 0
}
}
+
+type AlignPosition uint
+
+const (
+ AlignTop AlignPosition = iota
+ AlignCenter
+ AlignBottom
+)
+
+func (s *Scrollable) Align(idx int, pos AlignPosition) {
+ switch pos {
+ case AlignTop:
+ s.scroll = idx
+ case AlignCenter:
+ s.scroll = idx - s.height/2
+ case AlignBottom:
+ s.scroll = idx - s.height + 1
+ }
+ s.checkBounds()
+}