This seems to stem from the slow computations in the Update method (see artificial 100ms delay), these slow computations should probably handled in a tea.Cmd instead but I find this behavior still weird.
I just did some additional testing and this can also happen with slow View computations.
Setup:
Please complete the following information along with version numbers, if applicable.
OS: arch
Shell: zsh
Terminal Emulator: alacritty
Terminal Multiplexer: N/A
To Reproduce:
Steps to reproduce the behavior:
Run the source code below go run main.go
run tail -f debug.log
Click and drag the mouse around
See tea.KeyMsg in logs
Source Code:
package main
import (
"log"
"time"
"github.com/charmbracelet/bubbletea"
)
type model struct{}
func (m model) Init() tea.Cmd {
return nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.MouseMsg:
time.Sleep(100 * time.Millisecond)
case tea.KeyMsg:
log.Printf("key: %#v", msg)
switch msg.String() {
case "ctrl+q":
return m, tea.Quit
}
}
return m, nil
}
func (m model) View() string {
return "Press Ctrl+Q to quit."
}
func main() {
logFile, err := tea.LogToFile("debug.log", "test")
if err != nil {
log.Panicln("failed to open debug log file:", err)
}
defer logFile.Close()
p := tea.NewProgram(model{}, tea.WithAltScreen(), tea.WithMouseCellMotion())
if _, err := p.Run(); err != nil {
log.Panicln("error while running:", err)
}
}
Describe the bug: When I enable
tea.WithMouseCellMotion()
and press my left mouse button and then drag sometimes aKeyMsg
is emitted. Example:This seems to stem from the slow computations in the
Update
method (see artificial 100ms delay), these slow computations should probably handled in atea.Cmd
instead but I find this behavior still weird.I just did some additional testing and this can also happen with slow
View
computations.Setup: Please complete the following information along with version numbers, if applicable.
arch
zsh
alacritty
N/A
To Reproduce: Steps to reproduce the behavior:
go run main.go
tail -f debug.log
tea.KeyMsg
in logsSource Code:
Expected behavior: No
tea.KeyMsg
being emitted