[GH-ISSUE #400] #Question: Howto set focus when coming back to a page #292

Closed
opened 2026-03-04 01:03:41 +03:00 by kerem · 0 comments
Owner

Originally created by @shaunenslin on GitHub (Feb 9, 2020).
Original GitHub issue: https://github.com/rivo/tview/issues/400

I have 2 pages setup and the idea is to treat them like tabs.

I have a global variable called focusPrimitive, which I set each time I setfocus.
However, when switching between pages, I can't get it to setfocus where I last was on that page. As a result, I cannot do any navigation, since it seems nothing has been set to focus.

See below for the code I am trying to do

// ui6SettingsPages setup pages to administer extracts and connections
func (p *Properties) ui6SettingsPages(usr rapiduser.RapidUser, v bool, aws *amazon.Amazon) {
	p.activeMenu = "Extracts"
	p.aws = aws
	p.rapidUser = usr
	p.settingsPage = p.ui7Pages()
	p.app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
		switch event.Key() {
		case tcell.KeyCtrlC:
			// Exit the application
			p.app.Stop()
			os.Exit(0)
			return nil
		case tcell.KeyF2:
			p.settingsPage.SwitchToPage("Connections")
			p.activeMenu = "Connections"
			p.app.SetFocus(p.focusPrimitive)
		case tcell.KeyF1:
			p.settingsPage.SwitchToPage("Extracts")
			p.activeMenu = "Extracts"
			p.app.SetFocus(p.focusPrimitive)
		}
		return event
	})
	if err := p.app.SetRoot(p.settingsPage, true).SetFocus(p.settingsPage).Run(); err != nil {
		panic(err)
	}
}
Originally created by @shaunenslin on GitHub (Feb 9, 2020). Original GitHub issue: https://github.com/rivo/tview/issues/400 I have 2 pages setup and the idea is to treat them like tabs. I have a global variable called focusPrimitive, which I set each time I setfocus. However, when switching between pages, I can't get it to setfocus where I last was on that page. As a result, I cannot do any navigation, since it seems nothing has been set to focus. See below for the code I am trying to do ```` // ui6SettingsPages setup pages to administer extracts and connections func (p *Properties) ui6SettingsPages(usr rapiduser.RapidUser, v bool, aws *amazon.Amazon) { p.activeMenu = "Extracts" p.aws = aws p.rapidUser = usr p.settingsPage = p.ui7Pages() p.app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { switch event.Key() { case tcell.KeyCtrlC: // Exit the application p.app.Stop() os.Exit(0) return nil case tcell.KeyF2: p.settingsPage.SwitchToPage("Connections") p.activeMenu = "Connections" p.app.SetFocus(p.focusPrimitive) case tcell.KeyF1: p.settingsPage.SwitchToPage("Extracts") p.activeMenu = "Extracts" p.app.SetFocus(p.focusPrimitive) } return event }) if err := p.app.SetRoot(p.settingsPage, true).SetFocus(p.settingsPage).Run(); err != nil { panic(err) } } ````
kerem closed this issue 2026-03-04 01:03:41 +03:00
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#292
No description provided.