Add mouse events for --bind

Close #3473
This commit is contained in:
Junegunn Choi 2023-10-10 18:58:22 +09:00
parent a0d61b4c37
commit 391aa14845
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
5 changed files with 92 additions and 12 deletions

View File

@ -39,6 +39,22 @@ CHANGELOG
curl localhost:6266 -H "x-api-key: $FZF_API_KEY" -d 'change-query(yo)'
```
- Added `toggle-header` action
- Added mouse events for `--bind`
- `scroll-up` (bound to `up`)
- `scroll-down` (bound to `down`)
- `shift-scroll-up` (bound to `toggle+up`)
- `shift-scroll-down` (bound to `toggle+down`)
- `shift-left-click` (bound to `toggle`)
- `shift-right-click` (bound to `toggle`)
- `preview-scroll-up` (bound to `preview-up`)
- `preview-scroll-down` (bound to `preview-down`)
```sh
# Twice faster scrolling both in the main window and the preview window
fzf --bind 'scroll-up:up+up,scroll-down:down+down' \
--bind 'preview-scroll-up:preview-up+preview-up' \
--bind 'preview-scroll-down:preview-down+preview-down' \
--preview 'cat {}'
```
- Shell extensions
- bash key bindings no longer requires perl; it will use awk or mawk
instead if perl is not found

View File

@ -1012,6 +1012,22 @@ e.g.
.br
\fIdouble-click\fR
.br
\fIscroll-up\fR
.br
\fIscroll-down\fR
.br
\fIpreview-scroll-up\fR
.br
\fIpreview-scroll-down\fR
.br
\fIshift-left-click\fR
.br
\fIshift-right-click\fR
.br
\fIshift-scroll-up\fR
.br
\fIshift-scroll-down\fR
.br
or any single character
.SS AVAILABLE EVENTS:

View File

@ -702,8 +702,24 @@ func parseKeyChordsImpl(str string, message string, exit func(string)) map[tui.E
add(tui.LeftClick)
case "right-click":
add(tui.RightClick)
case "shift-left-click":
add(tui.SLeftClick)
case "shift-right-click":
add(tui.SRightClick)
case "double-click":
add(tui.DoubleClick)
case "scroll-up":
add(tui.ScrollUp)
case "scroll-down":
add(tui.ScrollDown)
case "shift-scroll-up":
add(tui.SScrollUp)
case "shift-scroll-down":
add(tui.SScrollDown)
case "preview-scroll-up":
add(tui.PreviewScrollUp)
case "preview-scroll-down":
add(tui.PreviewScrollDown)
case "f10":
add(tui.F10)
case "f11":

View File

@ -525,6 +525,16 @@ func defaultKeymap() map[tui.Event][]*action {
add(tui.Mouse, actMouse)
add(tui.LeftClick, actIgnore)
add(tui.RightClick, actToggle)
add(tui.SLeftClick, actToggle)
add(tui.SRightClick, actToggle)
add(tui.ScrollUp, actUp)
add(tui.ScrollDown, actDown)
keymap[tui.SScrollUp.AsEvent()] = toActions(actToggle, actUp)
keymap[tui.SScrollDown.AsEvent()] = toActions(actToggle, actDown)
add(tui.PreviewScrollUp, actPreviewUp)
add(tui.PreviewScrollDown, actPreviewDown)
return keymap
}
@ -3483,13 +3493,23 @@ func (t *Terminal) Loop() {
// Scrolling
if me.S != 0 {
if t.window.Enclose(my, mx) && t.merger.Length() > 0 {
if t.multi > 0 && me.Mod {
toggle()
evt := tui.ScrollUp
if me.Mod {
evt = tui.SScrollUp
}
t.vmove(me.S, true)
req(reqList)
if me.S < 0 {
evt = tui.ScrollDown
if me.Mod {
evt = tui.SScrollDown
}
}
return doActions(actionsFor(evt))
} else if t.hasPreviewWindow() && t.pwindow.Enclose(my, mx) {
scrollPreviewBy(-me.S)
evt := tui.PreviewScrollUp
if me.S < 0 {
evt = tui.PreviewScrollDown
}
return doActions(actionsFor(evt))
}
break
}
@ -3580,15 +3600,19 @@ func (t *Terminal) Loop() {
// Prompt
t.cx = mx + t.xoffset
} else if my >= min {
// List
if t.vset(t.offset+my-min) && t.multi > 0 && me.Mod {
toggle()
}
t.vset(t.offset + my - min)
req(reqList)
if me.Left {
return doActions(actionsFor(tui.LeftClick))
evt := tui.RightClick
if me.Mod {
evt = tui.SRightClick
}
return doActions(actionsFor(tui.RightClick))
if me.Left {
evt = tui.LeftClick
if me.Mod {
evt = tui.SLeftClick
}
}
return doActions(actionsFor(evt))
}
}
case actReload, actReloadSync:

View File

@ -55,6 +55,14 @@ const (
DoubleClick
LeftClick
RightClick
SLeftClick
SRightClick
ScrollUp
ScrollDown
SScrollUp
SScrollDown
PreviewScrollUp
PreviewScrollDown
BTab
BSpace