diff --git a/cmd/root.go b/cmd/root.go index 8ce81d4346d77e3bf239442d695c2ea329fdcf0c..e27bc46adcf38ae4b36cfba8d0f518690091242f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -118,6 +118,8 @@ to assist developers in writing, debugging, and understanding code directly from tea.WithAltScreen(), tea.WithKeyReleases(), tea.WithUniformKeyLayout(), + tea.WithMouseCellMotion(), // Use cell motion instead of all motion to reduce event flooding + tea.WithFilter(tui.MouseEventFilter), // Filter mouse events based on focus state ) go app.Subscribe(program) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index de241faefe175713bee0da8d130c3176aa31ac57..13f6bfbabb6b56e68c5b9519730e51257a4039f8 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -265,6 +265,7 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } } + m.textarea, cmd = m.textarea.Update(msg) cmds = append(cmds, cmd) return m, tea.Batch(cmds...) diff --git a/internal/tui/page/chat/chat.go b/internal/tui/page/chat/chat.go index 490f9aa216148c53f25af3df350374b30dee46a9..b0d5fce77caf8fc0398aa0b7feb4ede554ca1df4 100644 --- a/internal/tui/page/chat/chat.go +++ b/internal/tui/page/chat/chat.go @@ -68,6 +68,7 @@ const ( type ChatPage interface { util.Model layout.Help + IsChatFocused() bool } // cancelTimerCmd creates a command that expires the cancel timer @@ -557,3 +558,7 @@ func (p *chatPage) Bindings() []key.Binding { return bindings } + +func (p *chatPage) IsChatFocused() bool { + return p.focusedPane == PanelTypeChat +} diff --git a/internal/tui/tui.go b/internal/tui/tui.go index eec8e5595ae3d81fe0c92fd15efbfce0a791f1d8..28469caf2ed979eef89d90bdecb90b140154c77d 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -30,6 +30,29 @@ import ( "github.com/charmbracelet/lipgloss/v2" ) +// MouseEventFilter filters mouse events based on the current focus state +// This is used with tea.WithFilter to prevent mouse scroll events from +// interfering with typing performance in the editor +func MouseEventFilter(m tea.Model, msg tea.Msg) tea.Msg { + // Only filter mouse events + switch msg.(type) { + case tea.MouseWheelMsg, tea.MouseMotionMsg: + // Check if we have an appModel and if editor is focused + if appModel, ok := m.(*appModel); ok { + if appModel.currentPage == chat.ChatPageID { + if chatPage, ok := appModel.pages[appModel.currentPage].(chat.ChatPage); ok { + // If editor is focused (not chatFocused), filter out mouse wheel/motion events + if !chatPage.IsChatFocused() { + return nil // Filter out the event + } + } + } + } + } + // Allow all other events to pass through + return msg +} + // appModel represents the main application model that manages pages, dialogs, and UI state. type appModel struct { wWidth, wHeight int // Window dimensions