[gocui] Add PreviousX/PreviousY to ViewMouseBindingOpts

This is useful for detecting double-clicks.
This commit is contained in:
Stefan Haller 2025-03-26 13:08:45 +01:00
parent 153d0558b4
commit 5f149e2d07

View file

@ -92,6 +92,12 @@ type ViewMouseBinding struct {
type ViewMouseBindingOpts struct {
X int // i.e. origin x + cursor x
Y int // i.e. origin y + cursor y
// the previous cursor right before the click; useful because by the time
// the event is dispatched to handlers, gocui has already set the cursor to
// the new position. This is useful for detecting double clicks.
PreviousX int
PreviousY int
}
type GuiMutexes struct {
@ -1375,6 +1381,8 @@ func (g *Gui) onKey(ev *GocuiEvent) error {
newCx = lastCharForLine - v.ox
}
}
previousX := v.cx + v.ox
previousY := v.cy + v.oy
if !IsMouseScrollKey(ev.Key) {
v.SetCursor(newCx, newCy)
if v.Editable {
@ -1397,7 +1405,7 @@ func (g *Gui) onKey(ev *GocuiEvent) error {
}
if IsMouseKey(ev.Key) {
opts := ViewMouseBindingOpts{X: newX, Y: newY}
opts := ViewMouseBindingOpts{X: newX, Y: newY, PreviousX: previousX, PreviousY: previousY}
matched, err := g.execMouseKeybindings(v, ev, opts)
if err != nil {
return err