on main help sign in
Revert "feat(mouse): delegate mouse actions to terminal emulator (#218)"

This reverts commit 494274e6f47b53a6105cf8591043fbbde8c1882c.

commit3b786fbe53d856a74caee3a3769933b4efb86a60 authorChristian Rocha <christian@rocha.is> dateSat 19 Jul 2025, 10:16 (1 year ago) parent54f6cbe
2 files changed+27
cmd/root.go+2 internal/tui/tui.go+25
cmd/root.go+2
@@ -106,6 +106,8 @@ to assist developers in writing, debugging, and understanding code directly from
106106 tui.New(app),
107107 tea.WithAltScreen(),
108108 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
109111 )
110112
111113 go app.Subscribe(program)
internal/tui/tui.go+25
@@ -32,6 +32,29 @@ import (
3232 "github.com/charmbracelet/lipgloss/v2"
3333)
3434
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+
3558// appModel represents the main application model that manages pages, dialogs, and UI state.
3659type appModel struct {
3760 wWidth, wHeight int // Window dimensions
@@ -67,6 +90,8 @@ func (a appModel) Init() tea.Cmd {
6790 cmd = a.status.Init()
6891 cmds = append(cmds, cmd)
6992
93+ cmds = append(cmds, tea.EnableMouseAllMotion)
94+
7095 return tea.Batch(cmds...)
7196}
7297