mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-24 10:13:41 -05:00
Releasing a mouse button was delivered as a plain mouse-move (hover) event: the release processing resets dragState to NOT_DRAGGING, after which the event fell into the NOT_DRAGGING branch. Views therefore had no way of telling that a drag gesture ended, which the upcoming drag-based features (range selection, commit reordering) need. Deliver the release as a real mouse event with the MouseRelease key and normalize its modifiers to ModNone, so release bindings also match modified drags. Make recordClickInfo ignore it: a release is the end of a click, not a click of its own, and must not break double-click detection.
58 lines
2.0 KiB
Go
58 lines
2.0 KiB
Go
package gocui
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gdamore/tcell/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFirstMouseMovementAfterPressIsDragEvent(t *testing.T) {
|
|
t.Cleanup(resetMouseState)
|
|
resetMouseState()
|
|
|
|
pressEvent := gocuiEventFromTcellEvent(tcell.NewEventMouse(1, 2, tcell.ButtonPrimary, tcell.ModNone))
|
|
unchangedHeldEvent := gocuiEventFromTcellEvent(tcell.NewEventMouse(1, 2, tcell.ButtonPrimary, tcell.ModNone))
|
|
dragEvent := gocuiEventFromTcellEvent(tcell.NewEventMouse(1, 3, tcell.ButtonPrimary, tcell.ModNone))
|
|
|
|
assert.Equal(t, eventMouse, pressEvent.Type)
|
|
assert.Equal(t, MouseLeft, pressEvent.Key.KeyName())
|
|
assert.Equal(t, ModNone, pressEvent.Key.Mod())
|
|
assert.Equal(t, eventNone, unchangedHeldEvent.Type)
|
|
assert.Equal(t, eventMouse, dragEvent.Type)
|
|
assert.Equal(t, MouseLeft, dragEvent.Key.KeyName())
|
|
assert.Equal(t, ModMotion, dragEvent.Key.Mod())
|
|
}
|
|
|
|
func TestMouseReleaseAfterDragIsMouseEvent(t *testing.T) {
|
|
t.Cleanup(resetMouseState)
|
|
resetMouseState()
|
|
|
|
gocuiEventFromTcellEvent(tcell.NewEventMouse(1, 2, tcell.ButtonPrimary, tcell.ModNone))
|
|
gocuiEventFromTcellEvent(tcell.NewEventMouse(1, 3, tcell.ButtonPrimary, tcell.ModNone))
|
|
releaseEvent := gocuiEventFromTcellEvent(tcell.NewEventMouse(1, 3, tcell.ButtonNone, tcell.ModNone))
|
|
|
|
assert.Equal(t, eventMouse, releaseEvent.Type)
|
|
assert.Equal(t, MouseRelease, releaseEvent.Key.KeyName())
|
|
}
|
|
|
|
func TestMouseReleaseDoesNotKeepPressModifiers(t *testing.T) {
|
|
t.Cleanup(resetMouseState)
|
|
resetMouseState()
|
|
|
|
gocuiEventFromTcellEvent(tcell.NewEventMouse(1, 2, tcell.ButtonPrimary, tcell.ModAlt))
|
|
gocuiEventFromTcellEvent(tcell.NewEventMouse(1, 3, tcell.ButtonPrimary, tcell.ModAlt))
|
|
releaseEvent := gocuiEventFromTcellEvent(tcell.NewEventMouse(1, 3, tcell.ButtonNone, tcell.ModAlt))
|
|
|
|
assert.Equal(t, eventMouse, releaseEvent.Type)
|
|
assert.Equal(t, MouseRelease, releaseEvent.Key.KeyName())
|
|
assert.Equal(t, ModNone, releaseEvent.Key.Mod())
|
|
}
|
|
|
|
func resetMouseState() {
|
|
lastMouseKey = tcell.ButtonNone
|
|
dragState = NOT_DRAGGING
|
|
lastX = 0
|
|
lastY = 0
|
|
}
|