Skip to content
Myr

Support binding of left-click and right-click

Before adoption: this commit came in with the history the project adopted, so no landing records it.

left-click and right-click are respectively bound to "ignore" and "toggle" (after implicitly moving the cursor) by default. Close #1130

authored by Junegunn Choi · committed by Junegunn Choi · parent 9615c4e · Browse files · 6 files+31 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+31 added−10 removed

  • other:+31 added−10 removed

6 files+31 added−10 removed

modified:man/man1/fzf.1+3 added-1 removed
474 unmodified lines
475 \fIpgup\fR (\fIpage-up\fR)476 \fIpgdn\fR (\fIpage-down\fR)477 \fIshift-left\fR478 \fIshift-right\fR479 \fIleft-click\fR480 \fIright-click\fR481 \fIdouble-click\fR482 or any single character483484Additionally, a special event named \fIchange\fR is available which is
37 unmodified lines
522 \fBpreview-page-up\fR523 \fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)524 \fBprint-query\fR (print query and exit)525 \fBselect-all\fR524 \fBtoggle\fR526 \fBtoggle\fR (\fIright-click\fR)527 \fBtoggle-all\fR528 \fBtoggle+down\fR \fIctrl-i (tab)\fR529 \fBtoggle-in\fR (\fB--reverse\fR ? \fBtoggle+up\fR : \fBtoggle+down\fR)530 \fBtoggle-out\fR (\fB--reverse\fR ? \fBtoggle+down\fR : \fBtoggle+up\fR)
71 unmodified lines
modified:src/tui/light.go+7 added-4 removed
493 unmodified lines
494 return Event{Invalid, 0, nil}495 }496 *sz = 6497 switch r.buffer[3] {498 case 32, 36, 40, 48, // mouse-down / shift / cmd / ctrl498 case 32, 34, 36, 40, 48, // mouse-down / shift / cmd / ctrl499 35, 39, 43, 51: // mouse-up / shift / cmd / ctrl500 mod := r.buffer[3] >= 36501 left := r.buffer[3] == 32502 down := r.buffer[3]%2 == 0503 x := int(r.buffer[4] - 33)504 y := int(r.buffer[5]-33) - r.yoffset505 double := false506 if down {507 now := time.Now()508 if !left { // Right double click is not allowed509 r.clickY = []int{}507 if now.Sub(r.prevDownTime) < doubleClickDuration {510 } else if now.Sub(r.prevDownTime) < doubleClickDuration {511 r.clickY = append(r.clickY, y)512 } else {513 r.clickY = []int{y}514 }
4 unmodified lines
519 double = true520 }521 }522520 return Event{Mouse, 0, &MouseEvent{y, x, 0, down, double, mod}}523 return Event{Mouse, 0, &MouseEvent{y, x, 0, left, down, double, mod}}524 case 96, 100, 104, 112, // scroll-up / shift / cmd / ctrl525 97, 101, 105, 113: // scroll-down / shift / cmd / ctrl526 mod := r.buffer[3] >= 100527 s := 1 - int(r.buffer[3]%2)*2528 x := int(r.buffer[4] - 33)529 y := int(r.buffer[5]-33) - r.yoffset527 return Event{Mouse, 0, &MouseEvent{y, x, s, false, false, mod}}530 return Event{Mouse, 0, &MouseEvent{y, x, s, false, false, false, mod}}531 }532 return Event{Invalid, 0, nil}533}534
376 unmodified lines
modified:src/tui/tcell.go+8 added-5 removed
191 unmodified lines
192 x, y := ev.Position()193 button := ev.Buttons()194 mod := ev.Modifiers() != 0195 if button&tcell.WheelDown != 0 {196 return Event{Mouse, 0, &MouseEvent{y, x, -1, false, false, mod}}196 return Event{Mouse, 0, &MouseEvent{y, x, -1, false, false, false, mod}}197 } else if button&tcell.WheelUp != 0 {198 return Event{Mouse, 0, &MouseEvent{y, x, +1, false, false, mod}}198 return Event{Mouse, 0, &MouseEvent{y, x, +1, false, false, false, mod}}199 } else if runtime.GOOS != "windows" {200 // double and single taps on Windows don't quite work due to201 // the console acting on the events and not allowing us202 // to consume them.203204 down := button&tcell.Button1 != 0 // left204 left := button&tcell.Button1 != 0205 down := left || button&tcell.Button3 != 0206 double := false207 if down {208 now := time.Now()209 if !left {210 r.clickY = []int{}208 if now.Sub(r.prevDownTime) < doubleClickDuration {211 } else if now.Sub(r.prevDownTime) < doubleClickDuration {212 r.clickY = append(r.clickY, x)213 } else {214 r.clickY = []int{x}215 r.prevDownTime = now
4 unmodified lines
220 double = true221 }222 }223221 return Event{Mouse, 0, &MouseEvent{y, x, 0, down, double, mod}}224 return Event{Mouse, 0, &MouseEvent{y, x, 0, left, down, double, mod}}225 }226227 // process keyboard:228 case *tcell.EventKey:
358 unmodified lines
modified:src/tui/tui.go+3 added
42 unmodified lines
43 Invalid44 Resize45 Mouse46 DoubleClick47 LeftClick48 RightClick4950 BTab51 BSpace52
133 unmodified lines
186type MouseEvent struct {187 Y int188 X int189 S int190 Left bool191 Down bool192 Double bool193 Mod bool194}
230 unmodified lines
modified:src/options.go+4 added
428 unmodified lines
429 case "shift-left":430 chord = tui.SLeft431 case "shift-right":432 chord = tui.SRight433 case "left-click":434 chord = tui.LeftClick435 case "right-click":436 chord = tui.RightClick437 case "double-click":438 chord = tui.DoubleClick439 case "f10":440 chord = tui.F10
819 unmodified lines
modified:src/terminal.go+6 added
276 unmodified lines
277278 keymap[tui.Rune] = toActions(actRune)279 keymap[tui.Mouse] = toActions(actMouse)280 keymap[tui.DoubleClick] = toActions(actAccept)281 keymap[tui.LeftClick] = toActions(actIgnore)282 keymap[tui.RightClick] = toActions(actToggle)283 return keymap284}285286func trimQuery(query string) []rune {
1480 unmodified lines
1767 if t.vset(t.offset+my-min) && t.multi && me.Mod {1768 toggle()1769 }1770 req(reqList)1771 if me.Left {1772 return doActions(t.keymap[tui.LeftClick], tui.LeftClick)1773 }1774 return doActions(t.keymap[tui.RightClick], tui.RightClick)1775 }1776 }1777 }1778 }
92 unmodified lines