diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2023-10-10 18:58:22 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2023-10-11 09:42:12 +0900 |
commit | 391aa148451b6c0a5e17ec2453f35afaba046f1f (patch) | |
tree | d993649a5856240e37d9ecaec3612f241e5224c8 | |
parent | a0d61b4c373f6b977314f7ebe53f6236798151e9 (diff) |
Add mouse events for --bind
Close #3473
-rw-r--r-- | CHANGELOG.md | 16 | ||||
-rw-r--r-- | man/man1/fzf.1 | 16 | ||||
-rw-r--r-- | src/options.go | 16 | ||||
-rw-r--r-- | src/terminal.go | 46 | ||||
-rw-r--r-- | src/tui/tui.go | 8 |
5 files changed, 91 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index e2c51a4a..60a4710b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 28a772ea..5ea00276 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -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: diff --git a/src/options.go b/src/options.go index 3f4b5e92..1c650a2f 100644 --- a/src/options.go +++ b/src/options.go @@ -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": diff --git a/src/terminal.go b/src/terminal.go index 07525de3..56e472ce 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -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) + evt := tui.RightClick + if me.Mod { + evt = tui.SRightClick + } if me.Left { - return doActions(actionsFor(tui.LeftClick)) + evt = tui.LeftClick + if me.Mod { + evt = tui.SLeftClick + } } - return doActions(actionsFor(tui.RightClick)) + return doActions(actionsFor(evt)) } } case actReload, actReloadSync: diff --git a/src/tui/tui.go b/src/tui/tui.go index 4039565a..4625e9b5 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -55,6 +55,14 @@ const ( DoubleClick LeftClick RightClick + SLeftClick + SRightClick + ScrollUp + ScrollDown + SScrollUp + SScrollDown + PreviewScrollUp + PreviewScrollDown BTab BSpace |