diff --git a/application.go b/application.go index fc2d865..b7edf10 100644 --- a/application.go +++ b/application.go @@ -38,6 +38,7 @@ type FocusableComponent interface { type Application struct { screenLock sync.RWMutex screen tcell.Screen + prevMouseEvt *tcell.EventMouse root Component updates chan interface{} redrawTicker *time.Ticker @@ -50,6 +51,7 @@ const queueSize = 255 func NewApplication() *Application { return &Application{ + prevMouseEvt: &tcell.EventMouse{}, updates: make(chan interface{}, queueSize), redrawTicker: time.NewTicker(1 * time.Minute), stop: make(chan struct{}, 1), @@ -132,7 +134,10 @@ func (app *Application) Start() error { redraw = app.root.OnPasteEvent(customEvt) } case *tcell.EventMouse: - redraw = app.root.OnMouseEvent(event) + hasMotion := app.prevMouseEvt.Buttons() == event.Buttons() + customEvt := customMouseEvent{event, hasMotion} + app.prevMouseEvt = event + redraw = app.root.OnMouseEvent(customEvt) case *tcell.EventResize: clear = true redraw = true diff --git a/eventhandler.go b/eventhandler.go index 3d45b78..fa04259 100644 --- a/eventhandler.go +++ b/eventhandler.go @@ -38,6 +38,15 @@ type PasteEvent interface { Text() string } +type customMouseEvent struct { + *tcell.EventMouse + motion bool +} + +func (cme customMouseEvent) HasMotion() bool { + return cme.motion +} + // MouseEvent is an interface of the *tcell.EventMouse type. type MouseEvent interface { tcell.Event