nsxivc330b55
handle count prefix in thumbnail movements
+21 −18
5 files changed
- M README.md +1 −1
- M commands.c +1 −1
- M sxiv.1 +12 −4
- M thumbs.c +6 −11
- M thumbs.h +1 −1
| @@ -99,7 +99,7 @@ The following general key commands are available: | |||
| 99 | 99 | ||
| 100 | 100 | The following additional key commands are available in *thumbnail mode*: | |
| 101 | 101 | ||
| 102 | − | h,j,k,l Move selection left/down/up/right | |
| 102 | + | h,j,k,l Move selection left/down/up/right [count] times | |
| 103 | 103 | Ctrl-j,k Scroll thumbnail grid one window height down/up | |
| 104 | 104 | ||
| 105 | 105 | The following additional key commands are available in *image mode*: | |
| @@ -209,7 +209,7 @@ bool it_scroll_move(arg_t a) { | |||
| 209 | 209 | if (mode == MODE_IMAGE) | |
| 210 | 210 | return img_pan(&img, dir, prefix); | |
| 211 | 211 | else | |
| 212 | − | return tns_move_selection(&tns, dir); | |
| 212 | + | return tns_move_selection(&tns, dir, prefix); | |
| 213 | 213 | } | |
| 214 | 214 | ||
| 215 | 215 | bool it_scroll_screen(arg_t a) { | |
| @@ -126,16 +126,24 @@ Remove current image from file list and go to next image. | |||
| 126 | 126 | The following keyboard commands are only available in thumbnail mode: | |
| 127 | 127 | .TP | |
| 128 | 128 | .BR h ", " Left | |
| 129 | − | Move selection left. | |
| 129 | + | Move selection left | |
| 130 | + | .I count | |
| 131 | + | times. | |
| 130 | 132 | .TP | |
| 131 | 133 | .BR j ", " Down | |
| 132 | − | Move selection down. | |
| 134 | + | Move selection down | |
| 135 | + | .I count | |
| 136 | + | times. | |
| 133 | 137 | .TP | |
| 134 | 138 | .BR k ", " Up | |
| 135 | − | Move selection up. | |
| 139 | + | Move selection up | |
| 140 | + | .I count | |
| 141 | + | times. | |
| 136 | 142 | .TP | |
| 137 | 143 | .BR l ", " Right | |
| 138 | − | Move selection right. | |
| 144 | + | Move selection right | |
| 145 | + | .I count | |
| 146 | + | times. | |
| 139 | 147 | .TP | |
| 140 | 148 | .BR Ctrl-j ", " Ctrl-Down | |
| 141 | 149 | Scroll thumbnail grid one window height down. | |
| @@ -390,8 +390,9 @@ void tns_highlight(tns_t *tns, int n, bool hl) { | |||
| 390 | 390 | } | |
| 391 | 391 | } | |
| 392 | 392 | ||
| 393 | − | bool tns_move_selection(tns_t *tns, direction_t dir) { | |
| 393 | + | bool tns_move_selection(tns_t *tns, direction_t dir, int count) { | |
| 394 | 394 | int old; | |
| 395 | + | int c = (count > 0 ? count : 1); | |
| 395 | 396 | ||
| 396 | 397 | if (tns == NULL || tns->thumbs == NULL) | |
| 397 | 398 | return false; | |
| @@ -400,22 +401,16 @@ bool tns_move_selection(tns_t *tns, direction_t dir) { | |||
| 400 | 401 | ||
| 401 | 402 | switch (dir) { | |
| 402 | 403 | case DIR_UP: | |
| 403 | − | if (tns->sel >= tns->cols) | |
| 404 | − | tns->sel -= tns->cols; | |
| 404 | + | tns->sel = MAX(tns->sel - c * tns->cols, tns->sel % tns->cols); | |
| 405 | 405 | break; | |
| 406 | 406 | case DIR_DOWN: | |
| 407 | − | if (tns->sel + tns->cols < tns->cnt) | |
| 408 | − | tns->sel += tns->cols; | |
| 409 | − | else if (tns->sel < tns->cnt - tns->cnt % tns->cols) | |
| 410 | − | tns->sel = tns->cnt - 1; | |
| 407 | + | tns->sel = MIN(tns->sel + c * tns->cols, tns->cols * ((tns->cnt - 1) / tns->cols) + MIN((tns->cnt - 1) % tns->cols, tns->sel % tns->cols)); | |
| 411 | 408 | break; | |
| 412 | 409 | case DIR_LEFT: | |
| 413 | − | if (tns->sel > 0) | |
| 414 | − | tns->sel--; | |
| 410 | + | tns->sel = MAX(tns->sel - c, 0); | |
| 415 | 411 | break; | |
| 416 | 412 | case DIR_RIGHT: | |
| 417 | − | if (tns->sel < tns->cnt - 1) | |
| 418 | − | tns->sel++; | |
| 413 | + | tns->sel = MIN(tns->sel + c, tns->cnt - 1); | |
| 419 | 414 | break; | |
| 420 | 415 | } | |
| 421 | 416 | ||
| @@ -61,7 +61,7 @@ bool tns_load(tns_t*, int, const fileinfo_t*, bool, bool); | |||
| 61 | 61 | void tns_render(tns_t*); | |
| 62 | 62 | void tns_highlight(tns_t*, int, bool); | |
| 63 | 63 | ||
| 64 | − | bool tns_move_selection(tns_t*, direction_t); | |
| 64 | + | bool tns_move_selection(tns_t*, direction_t, int); | |
| 65 | 65 | bool tns_scroll(tns_t*, direction_t, bool); | |
| 66 | 66 | ||
| 67 | 67 | int tns_translate(tns_t*, int, int); | |