[GH-ISSUE #585] Mouse click breaks SetFocus #428

Closed
opened 2026-03-04 01:04:53 +03:00 by kerem · 3 comments
Owner

Originally created by @paulbdavis on GitHub (Mar 31, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/585

Setting up a view like this:


modal := tview.NewModal().
SetText("foo").
AddButtons([]string{"OK"}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
  input, view := getInputAndView()
  app.SetRoot(view, true).SetFocus(input)
})

app.SetRoot(modal, true).SetFocus(modal)

The return values from the mock function getInputAndView() are (*tview.InputField, tview.Primitive)

When I use the keyboard to dismiss the modal, the input is properly focused when the root and focus are set, but if I use the mouse to do it, it does not focus the input.

Calling SetFocus in a goroutine afterwards half fixes the problem; keyboard events are taken but the cursor does not display until typing starts

SetDoneFunc(func(buttonIndex int, buttonLabel string) {
  input, view := getInputAndView()
  app.SetRoot(view, true)
  go func(input *tview.InputField) {
    app.SetFocus(input)
  }(input)
})
Originally created by @paulbdavis on GitHub (Mar 31, 2021). Original GitHub issue: https://github.com/rivo/tview/issues/585 Setting up a view like this: ```go modal := tview.NewModal(). SetText("foo"). AddButtons([]string{"OK"}). SetDoneFunc(func(buttonIndex int, buttonLabel string) { input, view := getInputAndView() app.SetRoot(view, true).SetFocus(input) }) app.SetRoot(modal, true).SetFocus(modal) ``` The return values from the mock function `getInputAndView()` are `(*tview.InputField, tview.Primitive)` When I use the keyboard to dismiss the modal, the input is properly focused when the root and focus are set, but if I use the mouse to do it, it does not focus the input. Calling `SetFocus` in a goroutine afterwards half fixes the problem; keyboard events are taken but the cursor does not display until typing starts ```go SetDoneFunc(func(buttonIndex int, buttonLabel string) { input, view := getInputAndView() app.SetRoot(view, true) go func(input *tview.InputField) { app.SetFocus(input) }(input) }) ```
kerem closed this issue 2026-03-04 01:04:53 +03:00
Author
Owner

@rivo commented on GitHub (Apr 26, 2021):

I had a look at the tview code but it's not obvious how this can happen. Can you please post a small program (not just a snippet) that I can run that reproduces this issue?

<!-- gh-comment-id:826813799 --> @rivo commented on GitHub (Apr 26, 2021): I had a look at the `tview` code but it's not obvious how this can happen. Can you please post a small program (not just a snippet) that I can run that reproduces this issue?
Author
Owner

@rivo commented on GitHub (May 31, 2021):

Might be related to #612. If there are no further problems, I will close this issue soon.

<!-- gh-comment-id:851419759 --> @rivo commented on GitHub (May 31, 2021): Might be related to #612. If there are no further problems, I will close this issue soon.
Author
Owner

@gdamore commented on GitHub (Jun 17, 2021):

It certainly sounds like #612 to me.

<!-- gh-comment-id:862818775 --> @gdamore commented on GitHub (Jun 17, 2021): It certainly sounds like #612 to me.
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#428
No description provided.