mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-01-11 02:36:12 +00:00
Clicks with different x coordinates shouldn't be seen as a double-click
This commit is contained in:
parent
3761dc0433
commit
a893fc0ca2
@ -72,7 +72,7 @@ type LightRenderer struct {
|
|||||||
forceBlack bool
|
forceBlack bool
|
||||||
clearOnExit bool
|
clearOnExit bool
|
||||||
prevDownTime time.Time
|
prevDownTime time.Time
|
||||||
clickY []int
|
clicks [][2]int
|
||||||
ttyin *os.File
|
ttyin *os.File
|
||||||
buffer []byte
|
buffer []byte
|
||||||
origState *term.State
|
origState *term.State
|
||||||
@ -580,15 +580,15 @@ func (r *LightRenderer) mouseSequence(sz *int) Event {
|
|||||||
if down && !drag {
|
if down && !drag {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if !left { // Right double click is not allowed
|
if !left { // Right double click is not allowed
|
||||||
r.clickY = []int{}
|
r.clicks = [][2]int{}
|
||||||
} else if now.Sub(r.prevDownTime) < doubleClickDuration {
|
} else if now.Sub(r.prevDownTime) < doubleClickDuration {
|
||||||
r.clickY = append(r.clickY, y)
|
r.clicks = append(r.clicks, [2]int{x, y})
|
||||||
} else {
|
} else {
|
||||||
r.clickY = []int{y}
|
r.clicks = [][2]int{{x, y}}
|
||||||
}
|
}
|
||||||
r.prevDownTime = now
|
r.prevDownTime = now
|
||||||
} else {
|
} else {
|
||||||
if len(r.clickY) > 1 && r.clickY[0] == r.clickY[1] &&
|
if len(r.clicks) > 1 && r.clicks[0][0] == r.clicks[1][0] && r.clicks[0][1] == r.clicks[1][1] &&
|
||||||
time.Since(r.prevDownTime) < doubleClickDuration {
|
time.Since(r.prevDownTime) < doubleClickDuration {
|
||||||
double = true
|
double = true
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/gdamore/tcell/v2/encoding"
|
"github.com/gdamore/tcell/v2/encoding"
|
||||||
|
|
||||||
@ -218,54 +216,38 @@ func (r *FullscreenRenderer) GetChar() Event {
|
|||||||
return Event{Mouse, 0, &MouseEvent{y, x, -1, false, false, false, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, -1, false, false, false, mod}}
|
||||||
case button&tcell.WheelUp != 0:
|
case button&tcell.WheelUp != 0:
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, +1, false, false, false, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, +1, false, false, false, mod}}
|
||||||
case button&tcell.Button1 != 0 && !drag:
|
case button&tcell.Button1 != 0:
|
||||||
// all potential double click events put their 'line' coordinate in the clickY array
|
double := false
|
||||||
|
if !drag {
|
||||||
|
// all potential double click events put their coordinates in the clicks array
|
||||||
// double click event has two conditions, temporal and spatial, the first is checked here
|
// double click event has two conditions, temporal and spatial, the first is checked here
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if now.Sub(r.prevDownTime) < doubleClickDuration {
|
if now.Sub(r.prevDownTime) < doubleClickDuration {
|
||||||
r.clickY = append(r.clickY, y)
|
r.clicks = append(r.clicks, [2]int{x, y})
|
||||||
} else {
|
} else {
|
||||||
r.clickY = []int{y}
|
r.clicks = [][2]int{{x, y}}
|
||||||
}
|
}
|
||||||
r.prevDownTime = now
|
r.prevDownTime = now
|
||||||
|
|
||||||
// detect double clicks (also check for spatial condition)
|
// detect double clicks (also check for spatial condition)
|
||||||
n := len(r.clickY)
|
n := len(r.clicks)
|
||||||
double := n > 1 && r.clickY[n-2] == r.clickY[n-1]
|
double = n > 1 && r.clicks[n-2][0] == r.clicks[n-1][0] && r.clicks[n-2][1] == r.clicks[n-1][1]
|
||||||
if double {
|
if double {
|
||||||
// make sure two consecutive double clicks require four clicks
|
// make sure two consecutive double clicks require four clicks
|
||||||
r.clickY = []int{}
|
r.clicks = [][2]int{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fire single or double click event
|
// fire single or double click event
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, 0, true, !double, double, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, 0, true, !double, double, mod}}
|
||||||
case button&tcell.Button2 != 0 && !drag:
|
case button&tcell.Button2 != 0:
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, 0, false, true, false, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, 0, false, true, false, mod}}
|
||||||
case runtime.GOOS != "windows":
|
default:
|
||||||
|
|
||||||
// double and single taps on Windows don't quite work due to
|
// double and single taps on Windows don't quite work due to
|
||||||
// the console acting on the events and not allowing us
|
// the console acting on the events and not allowing us
|
||||||
// to consume them.
|
// to consume them.
|
||||||
|
|
||||||
left := button&tcell.Button1 != 0
|
left := button&tcell.Button1 != 0
|
||||||
down := left || button&tcell.Button3 != 0
|
down := left || button&tcell.Button3 != 0
|
||||||
double := false
|
double := false
|
||||||
if down {
|
|
||||||
now := time.Now()
|
|
||||||
if !left {
|
|
||||||
r.clickY = []int{}
|
|
||||||
} else if now.Sub(r.prevDownTime) < doubleClickDuration {
|
|
||||||
r.clickY = append(r.clickY, x)
|
|
||||||
} else {
|
|
||||||
r.clickY = []int{x}
|
|
||||||
r.prevDownTime = now
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if len(r.clickY) > 1 && r.clickY[0] == r.clickY[1] &&
|
|
||||||
time.Now().Sub(r.prevDownTime) < doubleClickDuration {
|
|
||||||
double = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, 0, left, down, double, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, 0, left, down, double, mod}}
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,7 @@ type FullscreenRenderer struct {
|
|||||||
mouse bool
|
mouse bool
|
||||||
forceBlack bool
|
forceBlack bool
|
||||||
prevDownTime time.Time
|
prevDownTime time.Time
|
||||||
clickY []int
|
clicks [][2]int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFullscreenRenderer(theme *ColorTheme, forceBlack bool, mouse bool) Renderer {
|
func NewFullscreenRenderer(theme *ColorTheme, forceBlack bool, mouse bool) Renderer {
|
||||||
@ -440,7 +440,7 @@ func NewFullscreenRenderer(theme *ColorTheme, forceBlack bool, mouse bool) Rende
|
|||||||
mouse: mouse,
|
mouse: mouse,
|
||||||
forceBlack: forceBlack,
|
forceBlack: forceBlack,
|
||||||
prevDownTime: time.Unix(0, 0),
|
prevDownTime: time.Unix(0, 0),
|
||||||
clickY: []int{}}
|
clicks: [][2]int{}}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user