Krolyxon
Commit c330b55

Branches

Refs →

nsxivc330b55

handle count prefix in thumbnail movements

Author
baskerville
Date
2012-07-15 10:30 +0200
Parent
4451f4a
Commit
c330b55de4035b058965d45989a14662b99a77a3

+21 −18

5 files changed

  1. M README.md +1 −1
  2. M commands.c +1 −1
  3. M sxiv.1 +12 −4
  4. M thumbs.c +6 −11
  5. M thumbs.h +1 −1
M README.md View
@@ -99,7 +99,7 @@ The following general key commands are available:
9999
100100 The following additional key commands are available in *thumbnail mode*:
101101
102− h,j,k,l Move selection left/down/up/right
102+ h,j,k,l Move selection left/down/up/right [count] times
103103 Ctrl-j,k Scroll thumbnail grid one window height down/up
104104
105105 The following additional key commands are available in *image mode*:
M commands.c View
@@ -209,7 +209,7 @@ bool it_scroll_move(arg_t a) {
209209 if (mode == MODE_IMAGE)
210210 return img_pan(&img, dir, prefix);
211211 else
212− return tns_move_selection(&tns, dir);
212+ return tns_move_selection(&tns, dir, prefix);
213213 }
214214
215215 bool it_scroll_screen(arg_t a) {
M sxiv.1 View
@@ -126,16 +126,24 @@ Remove current image from file list and go to next image.
126126 The following keyboard commands are only available in thumbnail mode:
127127 .TP
128128 .BR h ", " Left
129−Move selection left.
129+Move selection left
130+.I count
131+times.
130132 .TP
131133 .BR j ", " Down
132−Move selection down.
134+Move selection down
135+.I count
136+times.
133137 .TP
134138 .BR k ", " Up
135−Move selection up.
139+Move selection up
140+.I count
141+times.
136142 .TP
137143 .BR l ", " Right
138−Move selection right.
144+Move selection right
145+.I count
146+times.
139147 .TP
140148 .BR Ctrl-j ", " Ctrl-Down
141149 Scroll thumbnail grid one window height down.
M thumbs.c View
@@ -390,8 +390,9 @@ void tns_highlight(tns_t *tns, int n, bool hl) {
390390 }
391391 }
392392
393−bool tns_move_selection(tns_t *tns, direction_t dir) {
393+bool tns_move_selection(tns_t *tns, direction_t dir, int count) {
394394 int old;
395+ int c = (count > 0 ? count : 1);
395396
396397 if (tns == NULL || tns->thumbs == NULL)
397398 return false;
@@ -400,22 +401,16 @@ bool tns_move_selection(tns_t *tns, direction_t dir) {
400401
401402 switch (dir) {
402403 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);
405405 break;
406406 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));
411408 break;
412409 case DIR_LEFT:
413− if (tns->sel > 0)
414− tns->sel--;
410+ tns->sel = MAX(tns->sel - c, 0);
415411 break;
416412 case DIR_RIGHT:
417− if (tns->sel < tns->cnt - 1)
418− tns->sel++;
413+ tns->sel = MIN(tns->sel + c, tns->cnt - 1);
419414 break;
420415 }
421416
M thumbs.h View
@@ -61,7 +61,7 @@ bool tns_load(tns_t*, int, const fileinfo_t*, bool, bool);
6161 void tns_render(tns_t*);
6262 void tns_highlight(tns_t*, int, bool);
6363
64−bool tns_move_selection(tns_t*, direction_t);
64+bool tns_move_selection(tns_t*, direction_t, int);
6565 bool tns_scroll(tns_t*, direction_t, bool);
6666
6767 int tns_translate(tns_t*, int, int);