diff options
-rw-r--r-- | app.go | 13 | ||||
-rw-r--r-- | doc/senpai.1.scd | 7 | ||||
-rw-r--r-- | ui/buffers.go | 30 | ||||
-rw-r--r-- | ui/ui.go | 8 |
4 files changed, 56 insertions, 2 deletions
@@ -489,8 +489,17 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) { }) } case tcell.KeyRune: - app.win.InputRune(ev.Rune()) - app.typing() + if ev.Modifiers() == tcell.ModAlt { + switch ev.Rune() { + case 'n': + app.win.ScrollDownHighlight() + case 'p': + app.win.ScrollUpHighlight() + } + } else { + app.win.InputRune(ev.Rune()) + app.typing() + } default: return } diff --git a/doc/senpai.1.scd b/doc/senpai.1.scd index d5f5b92..df943aa 100644 --- a/doc/senpai.1.scd +++ b/doc/senpai.1.scd @@ -86,6 +86,13 @@ of messages are in the timeline: *ALT-END* Go to the last buffer. +*ALT-P* + Go to the previous highlight + +*ALT-N* + Go to the next highlight, or to the (most recent) end of the timeline if + there is none. + *UP*, *DOWN*, *LEFT*, *RIGHT*, *HOME*, *END*, *BACKSPACE*, *DELETE* Edit the text in the input field. diff --git a/ui/buffers.go b/ui/buffers.go index 0c24248..c126408 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -374,6 +374,36 @@ func (bs *BufferList) ScrollDown(n int) { } } +func (bs *BufferList) ScrollUpHighlight() bool { + b := &bs.list[bs.current] + ymin := b.scrollAmt + bs.tlHeight + y := 0 + for i := len(b.lines) - 1; 0 <= i; i-- { + line := &b.lines[i] + if ymin <= y && line.Highlight { + b.scrollAmt = y - bs.tlHeight + 1 + return true + } + y += len(line.NewLines(bs.tlInnerWidth)) + 1 + } + return false +} + +func (bs *BufferList) ScrollDownHighlight() bool { + b := &bs.list[bs.current] + yLastHighlight := 0 + y := 0 + for i := len(b.lines) - 1; 0 <= i && y < b.scrollAmt; i-- { + line := &b.lines[i] + if line.Highlight { + yLastHighlight = y + } + y += len(line.NewLines(bs.tlInnerWidth)) + 1 + } + b.scrollAmt = yLastHighlight + return b.scrollAmt != 0 +} + func (bs *BufferList) IsAtTop() bool { b := &bs.list[bs.current] return b.isAtTop @@ -132,6 +132,14 @@ func (ui *UI) ScrollDownBy(n int) { ui.bs.ScrollDown(n) } +func (ui *UI) ScrollUpHighlight() bool { + return ui.bs.ScrollUpHighlight() +} + +func (ui *UI) ScrollDownHighlight() bool { + return ui.bs.ScrollDownHighlight() +} + func (ui *UI) ScrollMemberUpBy(n int) { ui.memberOffset -= n if ui.memberOffset < 0 { |