From 65c9826bab96fe9925b7bc03caec2298f57a04a0 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Thu, 23 Nov 2017 21:33:33 +0000 Subject: Move remaining actions to bindable commands --- src/navigator.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/navigator.c') diff --git a/src/navigator.c b/src/navigator.c index 60e98af..9defcbc 100644 --- a/src/navigator.c +++ b/src/navigator.c @@ -130,7 +130,7 @@ const char *imv_navigator_selection(struct imv_navigator *nav) void imv_navigator_select_rel(struct imv_navigator *nav, int direction) { - int prev_path = nav->cur_path; + const int prev_path = nav->cur_path; if(nav->num_paths == 0) { return; } @@ -158,6 +158,29 @@ void imv_navigator_select_rel(struct imv_navigator *nav, int direction) return; } +void imv_navigator_select_abs(struct imv_navigator *nav, int index) +{ + const int prev_path = nav->cur_path; + /* allow -1 to indicate the last image */ + if(index < 0) { + index += nav->num_paths; + + /* but if they go farther back than the first image, stick to first image */ + if(index < 0) { + index = 0; + } + } + + /* stick to last image if we go beyond it */ + if(index >= nav->num_paths) { + index = nav->num_paths - 1; + } + + nav->cur_path = index; + nav->changed = prev_path != nav->cur_path; + nav->last_move_direction = (index >= prev_path) ? 1 : -1; +} + void imv_navigator_remove(struct imv_navigator *nav, const char *path) { int removed = -1; -- cgit v1.2.3