commit 9768535

Hubert Hirtz  ·  2021-10-26 16:41:19 +0000 UTC
parent 4cb5734
Scroll up/down highlight by highlight
4 files changed,  +56, -2
M app.go
M app.go
+11, -2
 1@@ -489,8 +489,17 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
 2 			})
 3 		}
 4 	case tcell.KeyRune:
 5-		app.win.InputRune(ev.Rune())
 6-		app.typing()
 7+		if ev.Modifiers() == tcell.ModAlt {
 8+			switch ev.Rune() {
 9+			case 'n':
10+				app.win.ScrollDownHighlight()
11+			case 'p':
12+				app.win.ScrollUpHighlight()
13+			}
14+		} else {
15+			app.win.InputRune(ev.Rune())
16+			app.typing()
17+		}
18 	default:
19 		return
20 	}
+7, -0
 1@@ -86,6 +86,13 @@ of messages are in the timeline:
 2 *ALT-END*
 3 	Go to the last buffer.
 4 
 5+*ALT-P*
 6+	Go to the previous highlight
 7+
 8+*ALT-N*
 9+	Go to the next highlight, or to the (most recent) end of the timeline if
10+	there is none.
11+
12 *UP*, *DOWN*, *LEFT*, *RIGHT*, *HOME*, *END*, *BACKSPACE*, *DELETE*
13 	Edit the text in the input field.
14 
+30, -0
 1@@ -374,6 +374,36 @@ func (bs *BufferList) ScrollDown(n int) {
 2 	}
 3 }
 4 
 5+func (bs *BufferList) ScrollUpHighlight() bool {
 6+	b := &bs.list[bs.current]
 7+	ymin := b.scrollAmt + bs.tlHeight
 8+	y := 0
 9+	for i := len(b.lines) - 1; 0 <= i; i-- {
10+		line := &b.lines[i]
11+		if ymin <= y && line.Highlight {
12+			b.scrollAmt = y - bs.tlHeight + 1
13+			return true
14+		}
15+		y += len(line.NewLines(bs.tlInnerWidth)) + 1
16+	}
17+	return false
18+}
19+
20+func (bs *BufferList) ScrollDownHighlight() bool {
21+	b := &bs.list[bs.current]
22+	yLastHighlight := 0
23+	y := 0
24+	for i := len(b.lines) - 1; 0 <= i && y < b.scrollAmt; i-- {
25+		line := &b.lines[i]
26+		if line.Highlight {
27+			yLastHighlight = y
28+		}
29+		y += len(line.NewLines(bs.tlInnerWidth)) + 1
30+	}
31+	b.scrollAmt = yLastHighlight
32+	return b.scrollAmt != 0
33+}
34+
35 func (bs *BufferList) IsAtTop() bool {
36 	b := &bs.list[bs.current]
37 	return b.isAtTop
+8, -0
 1@@ -132,6 +132,14 @@ func (ui *UI) ScrollDownBy(n int) {
 2 	ui.bs.ScrollDown(n)
 3 }
 4 
 5+func (ui *UI) ScrollUpHighlight() bool {
 6+	return ui.bs.ScrollUpHighlight()
 7+}
 8+
 9+func (ui *UI) ScrollDownHighlight() bool {
10+	return ui.bs.ScrollDownHighlight()
11+}
12+
13 func (ui *UI) ScrollMemberUpBy(n int) {
14 	ui.memberOffset -= n
15 	if ui.memberOffset < 0 {