From a14ecc3168f914a2bd3cf5c45944f52c364c7d8d Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Thu, 13 Jun 2019 06:14:41 +0200 Subject: [PATCH] Support moving to top / bottom --- m/pager.go | 11 +++++++++++ m/reader.go | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/m/pager.go b/m/pager.go index 68c0b4a..eaeeeae 100644 --- a/m/pager.go +++ b/m/pager.go @@ -77,6 +77,13 @@ func (p *_Pager) _OnKey(key tcell.Key) { case tcell.KeyDown: // Clipping is done in _AddLines() p.firstLineOneBased++ + + case tcell.KeyHome: + p.firstLineOneBased = 1 + + case tcell.KeyEnd: + p.firstLineOneBased = p.reader.LineCount() + 1 + } } @@ -84,6 +91,10 @@ func (p *_Pager) _OnRune(char rune) { switch char { case 'q': p._Quit() + case '<', 'g': + p.firstLineOneBased = 1 + case '>', 'G': + p.firstLineOneBased = p.reader.LineCount() + 1 } } diff --git a/m/reader.go b/m/reader.go index 71bf3c6..5cc5046 100644 --- a/m/reader.go +++ b/m/reader.go @@ -52,6 +52,10 @@ func NewReaderFromFilename(filename string) (*_Reader, error) { return NewReaderFromStream(stream) } +func (r *_Reader) LineCount() int { + return len(r.lines) +} + func (r *_Reader) GetLines(firstLineOneBased int, wantedLineCount int) *Lines { if firstLineOneBased < 1 { firstLineOneBased = 1