From d891191b780e5133f3042532d465edca4863d742 Mon Sep 17 00:00:00 2001 From: Chris Miller Date: Mon, 4 Nov 2019 06:55:58 +0000 Subject: [PATCH] Fire Selected on list item click --- demos/list/main.go | 1 + list.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/demos/list/main.go b/demos/list/main.go index 50cae17..3ca90eb 100644 --- a/demos/list/main.go +++ b/demos/list/main.go @@ -15,6 +15,7 @@ func main() { AddItem("Quit", "Press to exit", 'q', func() { app.Stop() }) + app.EnableMouse() if err := app.SetRoot(list, true).Run(); err != nil { panic(err) } diff --git a/list.go b/list.go index b36ef78..05c68d7 100644 --- a/list.go +++ b/list.go @@ -554,7 +554,17 @@ func (l *List) MouseHandler() func(event EventMouse) { atX, atY := event.Position() index := l.indexAtPoint(atX, atY) if index != -1 { - l.SetCurrentItem(index) + item := l.items[index] + if item.Selected != nil { + item.Selected() + } + if l.selected != nil { + l.selected(index, item.MainText, item.SecondaryText, item.Shortcut) + } + if index != l.currentItem && l.changed != nil { + l.changed(index, item.MainText, item.SecondaryText, item.Shortcut) + } + l.currentItem = index } } })