commit 4af3f68
delthas
·
2023-11-15 11:14:42 +0000 UTC
parent 5369aea
Fix vertical scrolling of buffers when navigating with keyboard
M
app.go
+7,
-7
1@@ -578,17 +578,17 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
2 app.win.ScrollDown()
3 case tcell.KeyCtrlN:
4 app.win.NextBuffer()
5- app.win.HorizontalBufferScrollTo()
6+ app.win.ScrollToBuffer()
7 case tcell.KeyCtrlP:
8 app.win.PreviousBuffer()
9- app.win.HorizontalBufferScrollTo()
10+ app.win.ScrollToBuffer()
11 case tcell.KeyRight:
12 if ev.Modifiers() == tcell.ModAlt {
13 app.win.NextBuffer()
14- app.win.HorizontalBufferScrollTo()
15+ app.win.ScrollToBuffer()
16 } else if ev.Modifiers() == tcell.ModShift {
17 app.win.NextUnreadBuffer()
18- app.win.HorizontalBufferScrollTo()
19+ app.win.ScrollToBuffer()
20 } else if ev.Modifiers() == tcell.ModCtrl {
21 app.win.InputRightWord()
22 } else {
23@@ -597,10 +597,10 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
24 case tcell.KeyLeft:
25 if ev.Modifiers() == tcell.ModAlt {
26 app.win.PreviousBuffer()
27- app.win.HorizontalBufferScrollTo()
28+ app.win.ScrollToBuffer()
29 } else if ev.Modifiers() == tcell.ModShift {
30 app.win.PreviousUnreadBuffer()
31- app.win.HorizontalBufferScrollTo()
32+ app.win.ScrollToBuffer()
33 } else if ev.Modifiers() == tcell.ModCtrl {
34 app.win.InputLeftWord()
35 } else {
36@@ -862,7 +862,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
37 // Restore last buffer
38 if netID == app.lastNetID && ev.Channel == app.lastBuffer {
39 app.win.JumpBufferNetwork(app.lastNetID, app.lastBuffer)
40- app.win.HorizontalBufferScrollTo()
41+ app.win.ScrollToBuffer()
42 app.lastNetID = ""
43 app.lastBuffer = ""
44 }
M
ui/ui.go
+12,
-10
1@@ -278,7 +278,7 @@ func (ui *UI) HasOverlay() bool {
2 func (ui *UI) AddBuffer(netID, netName, title string) (i int, added bool) {
3 i, added = ui.bs.Add(netID, netName, title)
4 if added {
5- ui.HorizontalBufferScrollTo()
6+ ui.ScrollToBuffer()
7 }
8 return
9 }
10@@ -455,7 +455,7 @@ func (ui *UI) Resize() {
11 } else {
12 ui.bs.ResizeTimeline(innerWidth, h-2, textWidth)
13 }
14- ui.HorizontalBufferScrollTo()
15+ ui.ScrollToBuffer()
16 ui.screen.Sync()
17 }
18
19@@ -510,20 +510,22 @@ func (ui *UI) Draw(members []irc.Member) {
20 ui.screen.Show()
21 }
22
23-func (ui *UI) HorizontalBufferScrollTo() {
24- w, _ := ui.screen.Size()
25- screenWidth := w - ui.memberWidth
26+func (ui *UI) ScrollToBuffer() {
27 if ui.bs.current < ui.channelOffset {
28 ui.channelOffset = ui.bs.current
29 return
30 }
31
32- leftMost := ui.bs.GetLeftMost(screenWidth)
33-
34- if ui.channelOffset >= leftMost {
35- return
36+ w, h := ui.screen.Size()
37+ var first int
38+ if ui.channelWidth > 0 {
39+ first = ui.bs.current - h + 1
40+ } else {
41+ first = ui.bs.GetLeftMost(w - ui.memberWidth)
42+ }
43+ if ui.channelOffset < first {
44+ ui.channelOffset = first
45 }
46- ui.channelOffset = leftMost
47 }
48
49 func (ui *UI) drawStatusBar(x0, y, width int) {