Fix #564: Option -l: number of lines to move on mouse scroll

This commit is contained in:
Arun Prakash Jana 2020-05-10 11:21:37 +05:30
parent 609561494f
commit 14beb0746f
No known key found for this signature in database
GPG key ID: A75979F35C080412
5 changed files with 18 additions and 4 deletions

View file

@ -23,6 +23,7 @@ _nnn ()
-g
-H
-K
-l
-n
-o
-p
@ -40,6 +41,8 @@ _nnn ()
if [[ $prev == -b ]]; then
local bookmarks=$(echo $NNN_BMS | awk -F: -v RS=\; '{print $1}')
COMPREPLY=( $(compgen -W "$bookmarks" -- "$cur") )
elif [[ $prev == -l ]]; then
return 1
elif [[ $prev == -p ]]; then
COMPREPLY=( $(compgen -f -d -- "$cur") )
elif [[ $prev == -s ]]; then

View file

@ -22,6 +22,7 @@ complete -c nnn -s F -d 'show fortune'
complete -c nnn -s g -d 'regex filters'
complete -c nnn -s H -d 'show hidden files'
complete -c nnn -s K -d 'detect key collision'
complete -c nnn -s l -r -d 'lines to move per scroll'
complete -c nnn -s n -d 'start in type-to-nav mode'
complete -c nnn -s o -d 'open files only on Enter'
complete -c nnn -s p -r -d 'copy selection to file' -a '-\tstdout'

View file

@ -20,6 +20,7 @@ args=(
'(-g)-g[regex filters]'
'(-H)-H[show hidden files]'
'(-K)-K[detect key collision]'
'(-l)-l[lines to move per scroll]:val'
'(-n)-n[start in type-to-nav mode]'
'(-o)-o[open files only on Enter]'
'(-p)-p[copy selection to file]:file name'

4
nnn.1
View file

@ -17,6 +17,7 @@
.Op Ar -g
.Op Ar -H
.Op Ar -K
.Op Ar -l
.Op Ar -n
.Op Ar -p file
.Op Ar -Q
@ -86,6 +87,9 @@ supports the following options:
.Fl K
test for keybind collision
.Pp
.Fl "l val"
number of lines to move per mouse wheel scroll
.Pp
.Fl n
start in type-to-nav mode
.Pp

View file

@ -324,7 +324,7 @@ static settings cfg = {
static context g_ctx[CTX_MAX] __attribute__ ((aligned));
static int ndents, cur, last, curscroll, last_curscroll, total_dents = ENTRY_INCR;
static int ndents, cur, last, curscroll, last_curscroll, total_dents = ENTRY_INCR, scroll_lines = 1;
static int nselected;
#ifndef NOFIFO
static int fifofd = -1;
@ -5391,14 +5391,14 @@ nochange:
#if NCURSES_MOUSE_VERSION > 1
/* Scroll up */
if (event.bstate == BUTTON4_PRESSED && ndents && (cfg.rollover || cur)) {
move_cursor((cur + ndents - 1) % ndents, 0);
move_cursor((cur + ndents - scroll_lines) % ndents, 0);
break;
}
/* Scroll down */
if (event.bstate == BUTTON5_PRESSED && ndents
&& (cfg.rollover || (cur != ndents - 1))) {
move_cursor((cur + 1) % ndents, 0);
move_cursor((cur + scroll_lines) % ndents, 0);
break;
}
#endif
@ -6689,6 +6689,7 @@ static void usage(void)
" -g regex filters [default: string]\n"
" -H show hidden files\n"
" -K detect key collision\n"
" -l val set scroll lines\n"
" -n type-to-nav mode\n"
" -o open files only on Enter\n"
" -p file selection file [stdout if '-']\n"
@ -6854,7 +6855,7 @@ int main(int argc, char *argv[])
while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id]
: getopt(argc, argv, "Ab:cdeEfFgHKnop:QrRs:St:T:Vxh"))) != -1) {
: getopt(argc, argv, "Ab:cdeEfFgHKl:nop:QrRs:St:T:Vxh"))) != -1) {
switch (opt) {
case 'A':
cfg.autoselect = 0;
@ -6893,6 +6894,10 @@ int main(int argc, char *argv[])
case 'K':
check_key_collision();
return EXIT_SUCCESS;
case 'l':
if (env_opts_id < 0)
scroll_lines = atoi(optarg);
break;
case 'n':
cfg.filtermode = 1;
break;