|
|
@ -1,6 +1,8 @@
|
|
|
|
package tview
|
|
|
|
package tview
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gdamore/tcell"
|
|
|
|
"github.com/gdamore/tcell"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -27,6 +29,8 @@ const (
|
|
|
|
WheelRight
|
|
|
|
WheelRight
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var DoubleClickInterval = 500 * time.Millisecond
|
|
|
|
|
|
|
|
|
|
|
|
// Does not set MouseMove or *Click actions.
|
|
|
|
// Does not set MouseMove or *Click actions.
|
|
|
|
func (action MouseAction) getMouseButtonAction(lastBtn, btn tcell.ButtonMask) MouseAction {
|
|
|
|
func (action MouseAction) getMouseButtonAction(lastBtn, btn tcell.ButtonMask) MouseAction {
|
|
|
|
btnDiff := btn ^ lastBtn
|
|
|
|
btnDiff := btn ^ lastBtn
|
|
|
@ -74,27 +78,33 @@ func (action MouseAction) getMouseButtonAction(lastBtn, btn tcell.ButtonMask) Mo
|
|
|
|
// Do not call if the mouse moved.
|
|
|
|
// Do not call if the mouse moved.
|
|
|
|
// Sets the *Click, including *DoubleClick.
|
|
|
|
// Sets the *Click, including *DoubleClick.
|
|
|
|
// This should be called last, after setting all the other flags.
|
|
|
|
// This should be called last, after setting all the other flags.
|
|
|
|
func (action MouseAction) getMouseClickAction(lastAct MouseAction) MouseAction {
|
|
|
|
func (action MouseAction) getMouseClickAction(lastAct MouseAction, lastClickTime *time.Time) MouseAction {
|
|
|
|
if action&MouseMove == 0 {
|
|
|
|
if action&MouseMove == 0 {
|
|
|
|
if action&MouseLeftUp != 0 {
|
|
|
|
if action&MouseLeftUp != 0 {
|
|
|
|
if lastAct&(MouseLeftClick|MouseLeftDoubleClick) == 0 {
|
|
|
|
if (*lastClickTime).Add(DoubleClickInterval).Before(time.Now()) {
|
|
|
|
action |= MouseLeftClick
|
|
|
|
action |= MouseLeftClick
|
|
|
|
} else if lastAct&MouseLeftDoubleClick == 0 {
|
|
|
|
*lastClickTime = time.Now()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
action |= MouseLeftDoubleClick
|
|
|
|
action |= MouseLeftDoubleClick
|
|
|
|
|
|
|
|
*lastClickTime = time.Time{} // reset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if action&MouseMiddleUp != 0 {
|
|
|
|
if action&MouseMiddleUp != 0 {
|
|
|
|
if lastAct&(MouseMiddleClick|MouseMiddleDoubleClick) == 0 {
|
|
|
|
if (*lastClickTime).Add(DoubleClickInterval).Before(time.Now()) {
|
|
|
|
action |= MouseMiddleClick
|
|
|
|
action |= MouseMiddleClick
|
|
|
|
} else if lastAct&MouseMiddleDoubleClick == 0 {
|
|
|
|
*lastClickTime = time.Now()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
action |= MouseMiddleDoubleClick
|
|
|
|
action |= MouseMiddleDoubleClick
|
|
|
|
|
|
|
|
*lastClickTime = time.Time{} // reset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if action&MouseRightUp != 0 {
|
|
|
|
if action&MouseRightUp != 0 {
|
|
|
|
if lastAct&(MouseRightClick|MouseRightDoubleClick) == 0 {
|
|
|
|
if (*lastClickTime).Add(DoubleClickInterval).Before(time.Now()) {
|
|
|
|
action |= MouseRightClick
|
|
|
|
action |= MouseRightClick
|
|
|
|
} else if lastAct&MouseRightDoubleClick == 0 {
|
|
|
|
*lastClickTime = time.Now()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
action |= MouseRightDoubleClick
|
|
|
|
action |= MouseRightDoubleClick
|
|
|
|
|
|
|
|
*lastClickTime = time.Time{} // reset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|