commit 2a9fc6e

Nick Hastings  ·  2023-07-03 09:08:42 +0000 UTC
parent c10c3f4
Implements NextUnreadBuffer and PreviousUnreadBuffer

These actions are bound to Shift+Right and Shift+Left.
4 files changed,  +40, -0
M app.go
M app.go
+4, -0
 1@@ -549,6 +549,8 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
 2 	case tcell.KeyRight:
 3 		if ev.Modifiers() == tcell.ModAlt {
 4 			app.win.NextBuffer()
 5+		} else if ev.Modifiers() == tcell.ModShift {
 6+			app.win.NextUnreadBuffer()
 7 		} else if ev.Modifiers() == tcell.ModCtrl {
 8 			app.win.InputRightWord()
 9 		} else {
10@@ -557,6 +559,8 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
11 	case tcell.KeyLeft:
12 		if ev.Modifiers() == tcell.ModAlt {
13 			app.win.PreviousBuffer()
14+		} else if ev.Modifiers() == tcell.ModShift {
15+			app.win.PreviousUnreadBuffer()
16 		} else if ev.Modifiers() == tcell.ModCtrl {
17 			app.win.InputLeftWord()
18 		} else {
+6, -0
 1@@ -86,6 +86,12 @@ senpai eats these events for eg selecting channels.*
 2 *CTRL-P*, *ALT-LEFT*
 3 	Go to the previous buffer.
 4 
 5+*SHIFT-RIGHT*
 6+	Go to the next unread buffer.
 7+
 8+*SHIFT-LEFT*
 9+	Go to the previous unread buffer.
10+
11 *ALT-HOME*
12 	Go to the first buffer.
13 
+20, -0
 1@@ -283,6 +283,26 @@ func (bs *BufferList) Previous() {
 2 	b.unread = false
 3 }
 4 
 5+func (bs *BufferList) NextUnread() {
 6+	for i := 0; i < len(bs.list); i++ {
 7+		c := (bs.current + i) % len(bs.list)
 8+		if bs.list[c].unread {
 9+			bs.To(c)
10+			return
11+		}
12+	}
13+}
14+
15+func (bs *BufferList) PreviousUnread() {
16+	for i := 0; i < len(bs.list); i++ {
17+		c := (bs.current - i + len(bs.list)) % len(bs.list)
18+		if bs.list[c].unread {
19+			bs.To(c)
20+			return
21+		}
22+	}
23+}
24+
25 func (bs *BufferList) Add(netID, netName, title string) (i int, added bool) {
26 	i = 0
27 	lTitle := strings.ToLower(title)
+10, -0
 1@@ -126,6 +126,16 @@ func (ui *UI) PreviousBuffer() {
 2 	ui.memberOffset = 0
 3 }
 4 
 5+func (ui *UI) NextUnreadBuffer() {
 6+	ui.bs.NextUnread()
 7+	ui.memberOffset = 0
 8+}
 9+
10+func (ui *UI) PreviousUnreadBuffer() {
11+	ui.bs.PreviousUnread()
12+	ui.memberOffset = 0
13+}
14+
15 func (ui *UI) ClickedBuffer() int {
16 	return ui.bs.clicked
17 }