From 2351421622f435a84dde96364c83b07a2c2339fe Mon Sep 17 00:00:00 2001 From: rkfg Date: Tue, 22 Jun 2021 16:34:41 +0300 Subject: [PATCH] Limit cursor movement in detail views --- ui/cursor/cursor.go | 6 +++++- ui/views/channel.go | 4 +++- ui/views/help.go | 4 +++- ui/views/routing.go | 3 +++ ui/views/transaction.go | 4 +++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ui/cursor/cursor.go b/ui/cursor/cursor.go index 0d5887c..8dac7e7 100644 --- a/ui/cursor/cursor.go +++ b/ui/cursor/cursor.go @@ -14,10 +14,14 @@ func Down(v View) error { return nil } cx, cy := v.Cursor() + ox, oy := v.Origin() _, _, sy, _ := v.Speed() + _, fs := v.Limits() + if cy+oy+sy >= fs { + return nil + } err := v.SetCursor(cx, cy+sy) if err != nil { - ox, oy := v.Origin() err := v.SetOrigin(ox, oy+sy) if err != nil { return err diff --git a/ui/views/channel.go b/ui/views/channel.go index 13c5898..ac84e83 100644 --- a/ui/views/channel.go +++ b/ui/views/channel.go @@ -49,7 +49,9 @@ func (c Channel) Speed() (int, int, int, int) { } func (c Channel) Limits() (pageSize int, fullSize int) { - return 0, 0 + _, pageSize = c.view.Size() + fullSize = len(c.view.BufferLines()) - 1 + return } func (c *Channel) SetCursor(x, y int) error { diff --git a/ui/views/help.go b/ui/views/help.go index 3387ede..19a11be 100644 --- a/ui/views/help.go +++ b/ui/views/help.go @@ -43,7 +43,9 @@ func (h Help) Speed() (int, int, int, int) { } func (h Help) Limits() (pageSize int, fullSize int) { - return 0, 0 + _, pageSize = h.view.Size() + fullSize = len(h.view.BufferLines()) - 1 + return } func (h *Help) SetCursor(x, y int) error { diff --git a/ui/views/routing.go b/ui/views/routing.go index 2c0fa43..694ef6f 100644 --- a/ui/views/routing.go +++ b/ui/views/routing.go @@ -137,6 +137,9 @@ func (c *Routing) Speed() (int, int, int, int) { func (c *Routing) Limits() (pageSize int, fullSize int) { _, pageSize = c.view.Size() fullSize = len(c.routingEvents.Log) + if pageSize < fullSize { + fullSize = pageSize + } return } diff --git a/ui/views/transaction.go b/ui/views/transaction.go index 257e016..62da79e 100644 --- a/ui/views/transaction.go +++ b/ui/views/transaction.go @@ -48,7 +48,9 @@ func (c Transaction) Speed() (int, int, int, int) { } func (c Transaction) Limits() (pageSize int, fullSize int) { - return 0, 0 + _, pageSize = c.view.Size() + fullSize = len(c.view.BufferLines()) - 1 + return } func (c *Transaction) SetCursor(x, y int) error {