on main help sign in
Revert "feat(mouse): delegate mouse actions to terminal emulator (#218)"
3b786fbChristian Rocha
cmd/root.go+2
@@ -106,6 +106,8 @@ to assist developers in writing, debugging, and understanding code directly from
106 tui.New(app),
106 tui.New(app),
107 tea.WithAltScreen(),
107 tea.WithAltScreen(),
108 tea.WithContext(ctx),
108 tea.WithContext(ctx),
109+ tea.WithMouseCellMotion(), // Use cell motion instead of all motion to reduce event flooding
110+ tea.WithFilter(tui.MouseEventFilter), // Filter mouse events based on focus state
109 )
111 )
110
112
111 go app.Subscribe(program)
113 go app.Subscribe(program)
internal/tui/tui.go+25
@@ -32,6 +32,29 @@ import (
32 "github.com/charmbracelet/lipgloss/v2"
32 "github.com/charmbracelet/lipgloss/v2"
33)
33)
34
34
35+// MouseEventFilter filters mouse events based on the current focus state
36+// This is used with tea.WithFilter to prevent mouse scroll events from
37+// interfering with typing performance in the editor
38+func MouseEventFilter(m tea.Model, msg tea.Msg) tea.Msg {
39+ // Only filter mouse events
40+ switch msg.(type) {
41+ case tea.MouseWheelMsg, tea.MouseMotionMsg:
42+ // Check if we have an appModel and if editor is focused
43+ if appModel, ok := m.(*appModel); ok {
44+ if appModel.currentPage == chat.ChatPageID {
45+ if chatPage, ok := appModel.pages[appModel.currentPage].(chat.ChatPage); ok {
46+ // If editor is focused (not chatFocused), filter out mouse wheel/motion events
47+ if !chatPage.IsChatFocused() {
48+ return nil // Filter out the event
49+ }
50+ }
51+ }
52+ }
53+ }
54+ // Allow all other events to pass through
55+ return msg
56+}
57+
35// appModel represents the main application model that manages pages, dialogs, and UI state.
58// appModel represents the main application model that manages pages, dialogs, and UI state.
36type appModel struct {
59type appModel struct {
37 wWidth, wHeight int // Window dimensions
60 wWidth, wHeight int // Window dimensions
@@ -67,6 +90,8 @@ func (a appModel) Init() tea.Cmd {
67 cmd = a.status.Init()
90 cmd = a.status.Init()
68 cmds = append(cmds, cmd)
91 cmds = append(cmds, cmd)
69
92
93+ cmds = append(cmds, tea.EnableMouseAllMotion)
94+
70 return tea.Batch(cmds...)
95 return tea.Batch(cmds...)
71}
96}
72
97