diff --git a/internal/cli/tui.go b/internal/cli/tui.go index 5094733..cb00d83 100644 --- a/internal/cli/tui.go +++ b/internal/cli/tui.go @@ -185,7 +185,7 @@ func (a *App) runInteractiveTUI(ctx context.Context, st *store.Store, repoID int return a.writeOutput("tui", payload, true) } model := newClusterBrowserModel(ctx, st, repoID, payload) - program := tea.NewProgram(model, tea.WithInput(os.Stdin), tea.WithOutput(out), tea.WithAltScreen(), tea.WithMouseCellMotion()) + program := tea.NewProgram(model, tea.WithInput(os.Stdin), tea.WithOutput(out), tea.WithAltScreen(), tea.WithMouseAllMotion()) finalModel, err := program.Run() if final, ok := finalModel.(clusterBrowserModel); ok && final.store != nil && final.store != st { _ = final.store.Close() @@ -1088,21 +1088,6 @@ func (m *clusterBrowserModel) handleMouse(msg tea.MouseMsg) { } func (m *clusterBrowserModel) handleMenuMouse(layout tuiLayout, msg tea.MouseMsg) { - switch msg.Button { - case tea.MouseButtonWheelUp: - m.menuIndex = m.nextSelectableMenuIndex(-1) - m.keepMenuVisible() - return - case tea.MouseButtonWheelDown: - m.menuIndex = m.nextSelectableMenuIndex(1) - m.keepMenuVisible() - return - case tea.MouseButtonRight: - if msg.Action == tea.MouseActionPress { - m.closeMenu("Menu closed") - } - return - } if msg.Action == tea.MouseActionMotion { index, ok := m.menuIndexAtMouse(layout, msg.X, msg.Y) if !ok { @@ -1120,6 +1105,21 @@ func (m *clusterBrowserModel) handleMenuMouse(layout tuiLayout, msg tea.MouseMsg } return } + switch msg.Button { + case tea.MouseButtonWheelUp: + m.menuIndex = m.nextSelectableMenuIndex(-1) + m.keepMenuVisible() + return + case tea.MouseButtonWheelDown: + m.menuIndex = m.nextSelectableMenuIndex(1) + m.keepMenuVisible() + return + case tea.MouseButtonRight: + if msg.Action == tea.MouseActionPress { + m.closeMenu("Menu closed") + } + return + } if msg.Button != tea.MouseButtonLeft || msg.Action != tea.MouseActionPress { return } diff --git a/internal/cli/tui_test.go b/internal/cli/tui_test.go index 58748c7..7ef39db 100644 --- a/internal/cli/tui_test.go +++ b/internal/cli/tui_test.go @@ -1275,7 +1275,7 @@ func TestTUIMouseMotionHoversFloatingMenuItems(t *testing.T) { model.menuOpen = true model.menuFloating = true model.menuRect = tuiRect{x: 5, y: 3, w: 40, h: 12} - model.menuOff = 2 + model.menuOff = 1 model.menuItems = make([]tuiMenuItem, 6) for index := range model.menuItems { model.menuItems[index] = tuiMenuItem{label: fmt.Sprintf("Item %d", index), action: "close-menu"} @@ -1283,7 +1283,7 @@ func TestTUIMouseMotionHoversFloatingMenuItems(t *testing.T) { model.handleMouse(tea.MouseMsg{ X: model.menuRect.x + 2, - Y: model.menuRect.y + 4, + Y: model.menuRect.y + 5, Action: tea.MouseActionMotion, Button: tea.MouseButtonNone, }) @@ -1291,6 +1291,20 @@ func TestTUIMouseMotionHoversFloatingMenuItems(t *testing.T) { if model.menuIndex != 3 { t.Fatalf("hover selected %d, want item 3", model.menuIndex) } + + model.handleMouse(tea.MouseMsg{ + X: model.menuRect.x + 2, + Y: model.menuRect.y + 6, + Action: tea.MouseActionMotion, + Button: tea.MouseButtonRight, + }) + + if model.menuIndex != 4 { + t.Fatalf("right-button hover selected %d, want item 4", model.menuIndex) + } + if !model.menuOpen { + t.Fatal("right-button motion should not close the menu") + } } func TestTUIRightClickClosesOpenMenu(t *testing.T) {