[GH-ISSUE #930] Unable to update adjacent view for the first item in the list #679

Open
opened 2026-03-04 01:06:59 +03:00 by kerem · 1 comment
Owner

Originally created by @peku-jamf on GitHub (Dec 21, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/930

Hello, can you please advice how can I update textView on the right side of the screen in case there is only one item in the list or there is no user interaction (no key pressed), thus no SetSelectedFunc() is triggered?

I assumed setting current item to the very first one would trigger callback, but it doesn't help.

Thanks

package main

import (
	"fmt"

	"github.com/gdamore/tcell/v2"
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()

	textView := tview.NewTextView().
		SetText("Item details").
		SetTextAlign(tview.AlignLeft).
		SetDynamicColors(true)

	list := tview.NewList().ShowSecondaryText(false).
		SetSelectedStyle(tcell.StyleDefault.Background(tcell.ColorDarkSlateGray).Foreground(tcell.ColorWhite)).
		AddItem("List item 1", "Some explanatory text", 'a', nil)


	list.SetSelectedFunc(func(i int, _ string, _ string, _ rune) {
		textView.SetText(fmt.Sprintf("Selected item %d", i))
	})

	list.SetChangedFunc(func(i int, _ string, _ string, _ rune) {
		textView.SetText(fmt.Sprintf("hovered item %d", i))
	})

	f := tview.NewFlex().
		SetDirection(tview.FlexColumn).
		AddItem(list, 0, 1, true).
		AddItem(textView, 0, 2, false)
	f.SetBorder(true)

	if err := app.SetRoot(f, true).SetFocus(list).Run(); err != nil {
		panic(err)
	}
}
Originally created by @peku-jamf on GitHub (Dec 21, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/930 Hello, can you please advice how can I update textView on the right side of the screen in case there is only one item in the list or there is no user interaction (no key pressed), thus no SetSelectedFunc() is triggered? I assumed setting current item to the very first one would trigger callback, but it doesn't help. Thanks ``` package main import ( "fmt" "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() textView := tview.NewTextView(). SetText("Item details"). SetTextAlign(tview.AlignLeft). SetDynamicColors(true) list := tview.NewList().ShowSecondaryText(false). SetSelectedStyle(tcell.StyleDefault.Background(tcell.ColorDarkSlateGray).Foreground(tcell.ColorWhite)). AddItem("List item 1", "Some explanatory text", 'a', nil) list.SetSelectedFunc(func(i int, _ string, _ string, _ rune) { textView.SetText(fmt.Sprintf("Selected item %d", i)) }) list.SetChangedFunc(func(i int, _ string, _ string, _ rune) { textView.SetText(fmt.Sprintf("hovered item %d", i)) }) f := tview.NewFlex(). SetDirection(tview.FlexColumn). AddItem(list, 0, 1, true). AddItem(textView, 0, 2, false) f.SetBorder(true) if err := app.SetRoot(f, true).SetFocus(list).Run(); err != nil { panic(err) } } ```
Author
Owner

@peku-jamf commented on GitHub (Dec 21, 2023):

I have workarounded the problem by adding an artificial list item, pointing to it, then returning back to first item and removing artificial one. But there must be a better way..

<!-- gh-comment-id:1866995309 --> @peku-jamf commented on GitHub (Dec 21, 2023): I have workarounded the problem by adding an artificial list item, pointing to it, then returning back to first item and removing artificial one. But there must be a better way..
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#679
No description provided.