mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-12-23 03:19:01 +00:00
Support binding of left-click and right-click
left-click and right-click are respectively bound to "ignore" and "toggle" (after implicitly moving the cursor) by default. Close #1130
This commit is contained in:
parent
9615c4edf1
commit
b3b101a89c
@ -476,6 +476,8 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
|
|||||||
\fIpgdn\fR (\fIpage-down\fR)
|
\fIpgdn\fR (\fIpage-down\fR)
|
||||||
\fIshift-left\fR
|
\fIshift-left\fR
|
||||||
\fIshift-right\fR
|
\fIshift-right\fR
|
||||||
|
\fIleft-click\fR
|
||||||
|
\fIright-click\fR
|
||||||
\fIdouble-click\fR
|
\fIdouble-click\fR
|
||||||
or any single character
|
or any single character
|
||||||
|
|
||||||
@ -521,7 +523,7 @@ triggered whenever the query string is changed.
|
|||||||
\fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)
|
\fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)
|
||||||
\fBprint-query\fR (print query and exit)
|
\fBprint-query\fR (print query and exit)
|
||||||
\fBselect-all\fR
|
\fBselect-all\fR
|
||||||
\fBtoggle\fR
|
\fBtoggle\fR (\fIright-click\fR)
|
||||||
\fBtoggle-all\fR
|
\fBtoggle-all\fR
|
||||||
\fBtoggle+down\fR \fIctrl-i (tab)\fR
|
\fBtoggle+down\fR \fIctrl-i (tab)\fR
|
||||||
\fBtoggle-in\fR (\fB--reverse\fR ? \fBtoggle+up\fR : \fBtoggle+down\fR)
|
\fBtoggle-in\fR (\fB--reverse\fR ? \fBtoggle+up\fR : \fBtoggle+down\fR)
|
||||||
|
@ -430,6 +430,10 @@ func parseKeyChords(str string, message string) map[int]string {
|
|||||||
chord = tui.SLeft
|
chord = tui.SLeft
|
||||||
case "shift-right":
|
case "shift-right":
|
||||||
chord = tui.SRight
|
chord = tui.SRight
|
||||||
|
case "left-click":
|
||||||
|
chord = tui.LeftClick
|
||||||
|
case "right-click":
|
||||||
|
chord = tui.RightClick
|
||||||
case "double-click":
|
case "double-click":
|
||||||
chord = tui.DoubleClick
|
chord = tui.DoubleClick
|
||||||
case "f10":
|
case "f10":
|
||||||
|
@ -278,6 +278,8 @@ func defaultKeymap() map[int][]action {
|
|||||||
keymap[tui.Rune] = toActions(actRune)
|
keymap[tui.Rune] = toActions(actRune)
|
||||||
keymap[tui.Mouse] = toActions(actMouse)
|
keymap[tui.Mouse] = toActions(actMouse)
|
||||||
keymap[tui.DoubleClick] = toActions(actAccept)
|
keymap[tui.DoubleClick] = toActions(actAccept)
|
||||||
|
keymap[tui.LeftClick] = toActions(actIgnore)
|
||||||
|
keymap[tui.RightClick] = toActions(actToggle)
|
||||||
return keymap
|
return keymap
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1766,6 +1768,10 @@ func (t *Terminal) Loop() {
|
|||||||
toggle()
|
toggle()
|
||||||
}
|
}
|
||||||
req(reqList)
|
req(reqList)
|
||||||
|
if me.Left {
|
||||||
|
return doActions(t.keymap[tui.LeftClick], tui.LeftClick)
|
||||||
|
}
|
||||||
|
return doActions(t.keymap[tui.RightClick], tui.RightClick)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -495,16 +495,19 @@ func (r *LightRenderer) mouseSequence(sz *int) Event {
|
|||||||
}
|
}
|
||||||
*sz = 6
|
*sz = 6
|
||||||
switch r.buffer[3] {
|
switch r.buffer[3] {
|
||||||
case 32, 36, 40, 48, // mouse-down / shift / cmd / ctrl
|
case 32, 34, 36, 40, 48, // mouse-down / shift / cmd / ctrl
|
||||||
35, 39, 43, 51: // mouse-up / shift / cmd / ctrl
|
35, 39, 43, 51: // mouse-up / shift / cmd / ctrl
|
||||||
mod := r.buffer[3] >= 36
|
mod := r.buffer[3] >= 36
|
||||||
|
left := r.buffer[3] == 32
|
||||||
down := r.buffer[3]%2 == 0
|
down := r.buffer[3]%2 == 0
|
||||||
x := int(r.buffer[4] - 33)
|
x := int(r.buffer[4] - 33)
|
||||||
y := int(r.buffer[5]-33) - r.yoffset
|
y := int(r.buffer[5]-33) - r.yoffset
|
||||||
double := false
|
double := false
|
||||||
if down {
|
if down {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if now.Sub(r.prevDownTime) < doubleClickDuration {
|
if !left { // Right double click is not allowed
|
||||||
|
r.clickY = []int{}
|
||||||
|
} else if now.Sub(r.prevDownTime) < doubleClickDuration {
|
||||||
r.clickY = append(r.clickY, y)
|
r.clickY = append(r.clickY, y)
|
||||||
} else {
|
} else {
|
||||||
r.clickY = []int{y}
|
r.clickY = []int{y}
|
||||||
@ -517,14 +520,14 @@ func (r *LightRenderer) mouseSequence(sz *int) Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, 0, down, double, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, 0, left, down, double, mod}}
|
||||||
case 96, 100, 104, 112, // scroll-up / shift / cmd / ctrl
|
case 96, 100, 104, 112, // scroll-up / shift / cmd / ctrl
|
||||||
97, 101, 105, 113: // scroll-down / shift / cmd / ctrl
|
97, 101, 105, 113: // scroll-down / shift / cmd / ctrl
|
||||||
mod := r.buffer[3] >= 100
|
mod := r.buffer[3] >= 100
|
||||||
s := 1 - int(r.buffer[3]%2)*2
|
s := 1 - int(r.buffer[3]%2)*2
|
||||||
x := int(r.buffer[4] - 33)
|
x := int(r.buffer[4] - 33)
|
||||||
y := int(r.buffer[5]-33) - r.yoffset
|
y := int(r.buffer[5]-33) - r.yoffset
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, s, false, false, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, s, false, false, false, mod}}
|
||||||
}
|
}
|
||||||
return Event{Invalid, 0, nil}
|
return Event{Invalid, 0, nil}
|
||||||
}
|
}
|
||||||
|
@ -193,19 +193,22 @@ func (r *FullscreenRenderer) GetChar() Event {
|
|||||||
button := ev.Buttons()
|
button := ev.Buttons()
|
||||||
mod := ev.Modifiers() != 0
|
mod := ev.Modifiers() != 0
|
||||||
if button&tcell.WheelDown != 0 {
|
if button&tcell.WheelDown != 0 {
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, -1, false, false, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, -1, false, false, false, mod}}
|
||||||
} else if button&tcell.WheelUp != 0 {
|
} else if button&tcell.WheelUp != 0 {
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, +1, false, false, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, +1, false, false, false, mod}}
|
||||||
} else if runtime.GOOS != "windows" {
|
} else if runtime.GOOS != "windows" {
|
||||||
// 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.
|
||||||
|
|
||||||
down := button&tcell.Button1 != 0 // left
|
left := button&tcell.Button1 != 0
|
||||||
|
down := left || button&tcell.Button3 != 0
|
||||||
double := false
|
double := false
|
||||||
if down {
|
if down {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if now.Sub(r.prevDownTime) < doubleClickDuration {
|
if !left {
|
||||||
|
r.clickY = []int{}
|
||||||
|
} else if now.Sub(r.prevDownTime) < doubleClickDuration {
|
||||||
r.clickY = append(r.clickY, x)
|
r.clickY = append(r.clickY, x)
|
||||||
} else {
|
} else {
|
||||||
r.clickY = []int{x}
|
r.clickY = []int{x}
|
||||||
@ -218,7 +221,7 @@ func (r *FullscreenRenderer) GetChar() Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, 0, down, double, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, 0, left, down, double, mod}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// process keyboard:
|
// process keyboard:
|
||||||
|
@ -44,6 +44,8 @@ const (
|
|||||||
Resize
|
Resize
|
||||||
Mouse
|
Mouse
|
||||||
DoubleClick
|
DoubleClick
|
||||||
|
LeftClick
|
||||||
|
RightClick
|
||||||
|
|
||||||
BTab
|
BTab
|
||||||
BSpace
|
BSpace
|
||||||
@ -185,6 +187,7 @@ type MouseEvent struct {
|
|||||||
Y int
|
Y int
|
||||||
X int
|
X int
|
||||||
S int
|
S int
|
||||||
|
Left bool
|
||||||
Down bool
|
Down bool
|
||||||
Double bool
|
Double bool
|
||||||
Mod bool
|
Mod bool
|
||||||
|
Loading…
Reference in New Issue
Block a user