From 38d2293a10c54309e5b462b2b5609a3ee3a023b9 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 24 Jul 2026 08:09:30 +0200 Subject: [PATCH] Add test for double-click detection Add a test pinning down that a press/release/press sequence at the same position is detected as a double click. An upcoming commit starts delivering the release as a real mouse event to the click-recording code, which must not mistake it for a click of its own. --- pkg/gocui/double_click_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pkg/gocui/double_click_test.go diff --git a/pkg/gocui/double_click_test.go b/pkg/gocui/double_click_test.go new file mode 100644 index 000000000..b8d9f5f9c --- /dev/null +++ b/pkg/gocui/double_click_test.go @@ -0,0 +1,34 @@ +package gocui + +import ( + "testing" + + "github.com/gdamore/tcell/v3" + "github.com/stretchr/testify/assert" +) + +func TestMouseReleaseDoesNotBreakDoubleClickDetection(t *testing.T) { + t.Cleanup(resetMouseState) + resetMouseState() + g := newTestGui(t) + view, _ := g.SetView("list", 0, 0, 20, 10, 0) + doubleClicks := []bool{} + assert.NoError(t, g.SetViewClickBinding(&ViewMouseBinding{ + ViewName: "list", + Key: MouseLeft, + Handler: func(opts ViewMouseBindingOpts) error { + doubleClicks = append(doubleClicks, opts.IsDoubleClick) + return nil + }, + })) + + for _, event := range []GocuiEvent{ + gocuiEventFromTcellEvent(tcell.NewEventMouse(view.x0+1, view.y0+1, tcell.ButtonPrimary, tcell.ModNone)), + gocuiEventFromTcellEvent(tcell.NewEventMouse(view.x0+1, view.y0+1, tcell.ButtonNone, tcell.ModNone)), + gocuiEventFromTcellEvent(tcell.NewEventMouse(view.x0+1, view.y0+1, tcell.ButtonPrimary, tcell.ModNone)), + } { + assert.NoError(t, g.onKey(&event)) + } + + assert.Equal(t, []bool{false, true}, doubleClicks) +}