Skip to content

Commit

Permalink
Bind Ctrl+MouseWheel to scroll up/down
Browse files Browse the repository at this point in the history
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). That should also allow usign 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
  • Loading branch information
ilyagr committed Dec 22, 2022
1 parent aa78b26 commit fa6d532
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ func init() {
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil, 1}
gOpts.keys["<pgup>"] = &callExpr{"page-up", nil, 1}
gOpts.keys["<c-y>"] = &callExpr{"scroll-up", nil, 1}
gOpts.keys["<c-m-up>"] = &callExpr{"scroll-up", nil, 1}
gOpts.keys["j"] = &callExpr{"down", nil, 1}
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
gOpts.keys["<m-down>"] = &callExpr{"down", nil, 1}
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil, 1}
gOpts.keys["<pgdn>"] = &callExpr{"page-down", nil, 1}
gOpts.keys["<c-e>"] = &callExpr{"scroll-down", nil, 1}
gOpts.keys["<c-m-down>"] = &callExpr{"scroll-down", nil, 1}
gOpts.keys["h"] = &callExpr{"updir", nil, 1}
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
gOpts.keys["l"] = &callExpr{"open", nil, 1}
Expand Down
12 changes: 9 additions & 3 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,12 +1189,18 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
case tcell.ButtonNone:
return nil
}
if tev.Modifiers() == tcell.ModCtrl {
button = "<c-" + button[1:]
}
if expr, ok := gOpts.keys[button]; ok {
return expr
}

if tev.Buttons() != tcell.Button1 && tev.Buttons() != tcell.Button2 {
return nil
if tev.Modifiers() == tcell.ModCtrl || (tev.Buttons() != tcell.Button1 && tev.Buttons() != tcell.Button2) {
ui.echoerrf("unknown mapping: %s", button)
ui.keyAcc = nil
ui.keyCount = nil
ui.menuBuf = nil
return draw
}

x, y := tev.Position()
Expand Down

0 comments on commit fa6d532

Please sign in to comment.