on main help sign in
feat(mouse): delegate mouse actions to terminal emulator (#218)
commit494274e6f47b53a6105cf8591043fbbde8c1882c authorbashbunni <15822994+bashbunni@users.noreply.github.com> dateFri 18 Jul 2025, 12:25 (1 year ago) parent7ee0eb0
2 files changed−27
cmd/root.go−2 internal/tui/tui.go−25
cmd/root.go−2
@@ -106,8 +106,6 @@ 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
111109 )
112110
113111 go app.Subscribe(program)
internal/tui/tui.go−25
@@ -31,29 +31,6 @@ import (
3131 "github.com/charmbracelet/lipgloss/v2"
3232)
3333
34−// MouseEventFilter filters mouse events based on the current focus state
35−// This is used with tea.WithFilter to prevent mouse scroll events from
36−// interfering with typing performance in the editor
37−func MouseEventFilter(m tea.Model, msg tea.Msg) tea.Msg {
38− // Only filter mouse events
39− switch msg.(type) {
40− case tea.MouseWheelMsg, tea.MouseMotionMsg:
41− // Check if we have an appModel and if editor is focused
42− if appModel, ok := m.(*appModel); ok {
43− if appModel.currentPage == chat.ChatPageID {
44− if chatPage, ok := appModel.pages[appModel.currentPage].(chat.ChatPage); ok {
45− // If editor is focused (not chatFocused), filter out mouse wheel/motion events
46− if !chatPage.IsChatFocused() {
47− return nil // Filter out the event
48− }
49− }
50− }
51− }
52− }
53− // Allow all other events to pass through
54− return msg
55−}
56−
5734// appModel represents the main application model that manages pages, dialogs, and UI state.
5835type appModel struct {
5936 wWidth, wHeight int // Window dimensions
@@ -88,8 +65,6 @@ func (a appModel) Init() tea.Cmd {
8865 cmd = a.status.Init()
8966 cmds = append(cmds, cmd)
9067
91− cmds = append(cmds, tea.EnableMouseAllMotion)
92−
9368 return tea.Batch(cmds...)
9469}
9570