[GH-ISSUE #315] list.SetChangedFunc is not called after list.SetCurrentItem #239

Closed
opened 2026-03-04 01:03:14 +03:00 by kerem · 1 comment
Owner

Originally created by @SamWhited on GitHub (Jun 25, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/315

The documentation for List.SetChangedFunc say:

This function is also called when the first item is added or when SetCurrentItem() is called.

However, this does not appear to be working. For example, if we modify the lists example to output selected items then call List.SetCurrentItem, nothing happens except that the list item is selected:

package main

import (
	"fmt"
	"time"

	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	list := tview.NewList().
		AddItem("List item 1", "Some explanatory text", 'a', nil).
		AddItem("List item 2", "Some explanatory text", 'b', nil).
		AddItem("List item 3", "Some explanatory text", 'c', nil).
		AddItem("List item 4", "Some explanatory text", 'd', nil).
		AddItem("Quit", "Press to exit", 'q', func() {
			app.Stop()
		})
	list.SetChangedFunc(func(index int, mainText string, secondaryText string, shortcut rune) {
		list.AddItem(fmt.Sprintf("Item %d selected", index), "", 0, nil)
	})
	go func() {
		time.Sleep(time.Second)

		list.SetCurrentItem(2)
		app.Draw()
	}()
	if err := app.SetRoot(list, true).Run(); err != nil {
		panic(err)
	}
}
Originally created by @SamWhited on GitHub (Jun 25, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/315 The documentation for [`List.SetChangedFunc`](https://godoc.org/github.com/rivo/tview#List.SetChangedFunc) say: > This function is also called when the first item is added or when SetCurrentItem() is called. However, this does not appear to be working. For example, if we modify the lists example to output selected items then call [`List.SetCurrentItem`](https://godoc.org/github.com/rivo/tview#List.SetCurrentItem), nothing happens except that the list item is selected: ```go package main import ( "fmt" "time" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() list := tview.NewList(). AddItem("List item 1", "Some explanatory text", 'a', nil). AddItem("List item 2", "Some explanatory text", 'b', nil). AddItem("List item 3", "Some explanatory text", 'c', nil). AddItem("List item 4", "Some explanatory text", 'd', nil). AddItem("Quit", "Press to exit", 'q', func() { app.Stop() }) list.SetChangedFunc(func(index int, mainText string, secondaryText string, shortcut rune) { list.AddItem(fmt.Sprintf("Item %d selected", index), "", 0, nil) }) go func() { time.Sleep(time.Second) list.SetCurrentItem(2) app.Draw() }() if err := app.SetRoot(list, true).Run(); err != nil { panic(err) } } ```
kerem closed this issue 2026-03-04 01:03:14 +03:00
Author
Owner

@rivo commented on GitHub (Jul 11, 2019):

Thanks. (I ended up not using your PR because I haven't set up unit test cases yet. Still on my todo list.)

<!-- gh-comment-id:510432605 --> @rivo commented on GitHub (Jul 11, 2019): Thanks. (I ended up not using your PR because I haven't set up unit test cases yet. Still on my todo list.)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#239
No description provided.