commit 23a895e
delthas
·
2024-12-09 17:12:07 +0000 UTC
parent d13c5b3
Fix scrolling to highlight on buffers with unread messages. Thanks to kucha on #senpai for finding this issue.
1 files changed,
+34,
-20
+34,
-20
1@@ -588,17 +588,16 @@ func (bs *BufferList) SetRead(netID, title string, timestamp time.Time) {
2
3 func (bs *BufferList) UpdateRead() (netID, title string, timestamp time.Time) {
4 b := bs.cur()
5- var line *Line
6- y := 0
7- for i := len(b.lines) - 1; 0 <= i; i-- {
8- line = &b.lines[i]
9+ var l *Line
10+ bs.forEachLine(b, func(line *Line, y int) bool {
11+ l = line
12 if y >= b.scrollAmt && line.Readable {
13- break
14+ return true
15 }
16- y += len(line.NewLines(bs.ui.vx, bs.textWidth)) + 1
17- }
18- if line != nil && line.At.After(b.read) {
19- b.read = line.At
20+ return false
21+ })
22+ if l != nil && l.At.After(b.read) {
23+ b.read = l.At
24 return b.netID, b.title, b.read
25 }
26 return "", "", time.Time{}
27@@ -637,29 +636,27 @@ func (bs *BufferList) ScrollDown(n int) {
28 func (bs *BufferList) ScrollUpHighlight() bool {
29 b := bs.cur()
30 ymin := b.scrollAmt + bs.tlHeight
31- y := 0
32- for i := len(b.lines) - 1; 0 <= i; i-- {
33- line := &b.lines[i]
34+ return bs.forEachLine(b, func(line *Line, y int) bool {
35 if ymin <= y && line.Highlight {
36 b.scrollAmt = y - bs.tlHeight + 1
37 return true
38 }
39- y += len(line.NewLines(bs.ui.vx, bs.textWidth)) + 1
40- }
41- return false
42+ return false
43+ })
44 }
45
46 func (bs *BufferList) ScrollDownHighlight() bool {
47 b := bs.cur()
48 yLastHighlight := 0
49- y := 0
50- for i := len(b.lines) - 1; 0 <= i && y < b.scrollAmt; i-- {
51- line := &b.lines[i]
52+ bs.forEachLine(b, func(line *Line, y int) bool {
53+ if y >= b.scrollAmt {
54+ return true
55+ }
56 if line.Highlight {
57 yLastHighlight = y
58 }
59- y += len(line.NewLines(bs.ui.vx, bs.textWidth)) + 1
60- }
61+ return false
62+ })
63 b.scrollAmt = yLastHighlight
64 return b.scrollAmt != 0
65 }
66@@ -700,6 +697,23 @@ func (bs *BufferList) cur() *buffer {
67 return &bs.list[bs.current]
68 }
69
70+func (bs *BufferList) forEachLine(b *buffer, f func(line *Line, y int) bool) bool {
71+ rulerDrawn := b.unreadSkip != optionalFalse || b.unreadRuler.IsZero() || b.title == ""
72+ y := 0
73+ for i := len(b.lines) - 1; 0 <= i; i-- {
74+ line := &b.lines[i]
75+ if !rulerDrawn && !line.At.After(b.unreadRuler) {
76+ rulerDrawn = true
77+ y++
78+ }
79+ if f(line, y) {
80+ return true
81+ }
82+ y += len(line.NewLines(bs.ui.vx, bs.textWidth)) + 1
83+ }
84+ return false
85+}
86+
87 func (bs *BufferList) DrawVerticalBufferList(vx *Vaxis, x0, y0, width, height int, offset *int) {
88 if y0+len(bs.list)-*offset < height {
89 *offset = y0 + len(bs.list) - height