~taiite/public-inbox

senpai: Switch to channel when horizontal channel list is clicked v1 PROPOSED

mooff: 1
 Switch to channel when horizontal channel list is clicked

 3 files changed, 35 insertions(+), 3 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~taiite/public-inbox/patches/31146/mbox | git am -3
Learn more about email & git

[PATCH senpai] Switch to channel when horizontal channel list is clicked Export this patch

---
 app.go        | 12 +++++++++---
 ui/buffers.go | 22 ++++++++++++++++++++++
 ui/ui.go      |  4 ++++
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/app.go b/app.go
index 4c63e29..e1d8216 100644
--- a/app.go
+++ b/app.go
@@ -426,9 +426,15 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
			app.win.ScrollDownBy(4)
		}
	}
	if ev.Buttons()&tcell.ButtonPrimary != 0 && x < app.win.Config().ChanColWidth {
		app.win.ClickBuffer(y + app.win.ChannelOffset())
		app.win.GoToBufferNo(y + app.win.ChannelOffset())
	if ev.Buttons()&tcell.ButtonPrimary != 0 {
		if x < app.win.Config().ChanColWidth {
			app.win.ClickBuffer(y + app.win.ChannelOffset())
			app.win.GoToBufferNo(y + app.win.ChannelOffset())
		} else if w, h := app.win.Size(); y == h-1 {
			if i := app.win.BufferUnderMouseHorizontal(x, w); i != -1 {
				app.win.GoToBufferNo(i)
			}
		}
	}
	if ev.Buttons() == 0 {
		if x < app.win.Config().ChanColWidth {
diff --git a/ui/buffers.go b/ui/buffers.go
index 1ccb921..20627f9 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -628,3 +628,25 @@ func (bs *BufferList) DrawTimeline(screen tcell.Screen, x0, y0, nickColWidth int

	b.isAtTop = y0 <= yi
}

func (bs *BufferList) IndexFromMouseHorizontal(mouseX, x0, width int) int {
	x := x0
	for i, b := range bs.list {
		if width <= x-x0 {
			break
		}
		var title = b.title
		if title == "" {
			title = b.netName
		}
		x += stringWidth(truncate(title, width-x, "\u2026"))
		if 0 < b.highlights {
			x += 2
		}
		x++
		if mouseX < x {
			return i
		}
	}
	return -1
}
diff --git a/ui/ui.go b/ui/ui.go
index 492411d..289dd27 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -108,6 +108,10 @@ func (ui *UI) PreviousBuffer() {
	ui.memberOffset = 0
}

func (ui *UI) BufferUnderMouseHorizontal(mouseX, screenW int) int {
	return ui.bs.IndexFromMouseHorizontal(mouseX, 0, screenW-ui.config.MemberColWidth)
}

func (ui *UI) ClickedBuffer() int {
	return ui.bs.clicked
}
-- 
2.30.2
Thanks for the patch.

I have implemented a similar feature by adapting your patch.

See: 180940b653d1f9b46b164292e91a53aedd88d48d