From 2fe5e4d54e4cb015dc4201cf612b053cda72e2a3 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Sat, 11 Feb 2023 08:58:44 -0800 Subject: [PATCH] Bind Ctrl+MouseWheel to scroll up/down (#1051) On my system, Shift+Mouse is captured by the terminal and Alt+Mouse only works for one of the alt keys. Hence I picked Ctrl. This also allows binding of Ctrl+MouseButtons (but doesn't set any such bindings). As a minor bonus, that should allow using Ctrl+Click to select `lf`'s terminal without moving the cursor no matter where you click. On tmux, this doesn't work out of the box and requires a change to `tmux.conf` along the following lines: bind-key -T root C-MouseDown1Pane select-pane -t = \; send-keys -M You can omit the `send-keys -M` if you never want to pass `Ctrl+Click` to any of your terminal apps. (Then it will work without this PR). --- doc.go | 2 +- docstring.go | 2 +- lf.1 | 2 +- opts.go | 2 ++ ui.go | 12 +++++++++--- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc.go b/doc.go index f0897102..2dd6daee 100644 --- a/doc.go +++ b/doc.go @@ -226,7 +226,7 @@ If the 'mouse' option is enabled, mouse buttons have the following default effec Enter a directory or open a file. Also works on the preview window. Scroll wheel - Scroll up or down. + Move up or down. If Ctrl is pressed, scroll up or down. # Configuration diff --git a/docstring.go b/docstring.go index 9d9fe9a9..f892fdc3 100644 --- a/docstring.go +++ b/docstring.go @@ -231,7 +231,7 @@ effects: Enter a directory or open a file. Also works on the preview window. Scroll wheel - Scroll up or down. + Move up or down. If Ctrl is pressed, scroll up or down. # Configuration diff --git a/lf.1 b/lf.1 index d8206969..2454f83b 100644 --- a/lf.1 +++ b/lf.1 @@ -259,7 +259,7 @@ If the 'mouse' option is enabled, mouse buttons have the following default effec .PP .EX Scroll wheel - Scroll up or down. + Move up or down. If Ctrl is pressed, scroll up or down. .EE .SH CONFIGURATION Configuration files should be located at: diff --git a/opts.go b/opts.go index 18a11df6..f507c6bc 100644 --- a/opts.go +++ b/opts.go @@ -139,6 +139,7 @@ func init() { gOpts.keys[""] = &callExpr{"page-up", nil, 1} gOpts.keys[""] = &callExpr{"page-up", nil, 1} gOpts.keys[""] = &callExpr{"scroll-up", nil, 1} + gOpts.keys[""] = &callExpr{"scroll-up", nil, 1} gOpts.keys["j"] = &callExpr{"down", nil, 1} gOpts.keys[""] = &callExpr{"down", nil, 1} gOpts.keys[""] = &callExpr{"down", nil, 1} @@ -146,6 +147,7 @@ func init() { gOpts.keys[""] = &callExpr{"page-down", nil, 1} gOpts.keys[""] = &callExpr{"page-down", nil, 1} gOpts.keys[""] = &callExpr{"scroll-down", nil, 1} + gOpts.keys[""] = &callExpr{"scroll-down", nil, 1} gOpts.keys["h"] = &callExpr{"updir", nil, 1} gOpts.keys[""] = &callExpr{"updir", nil, 1} gOpts.keys["l"] = &callExpr{"open", nil, 1} diff --git a/ui.go b/ui.go index 2ed56c81..2d888836 100644 --- a/ui.go +++ b/ui.go @@ -1182,12 +1182,18 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr { case tcell.ButtonNone: return nil } + if tev.Modifiers() == tcell.ModCtrl { + button = "